I'm getting a " incorrect syntax near ',' " no matter what I try to do. Is there any place where the precise and demanding rules for stringing together SQL commands is explained? For example what do [] signify, and when should it be used? I assume that only a table column name should go between those two characters - is that true? Also, how do you represent an alphanumeric literal? 'abc'? What about a numeric literal - do you put some sort of quotes around it? What about a function - and where is there a list of valid functions representing today's date, the current time, the current user name?
I'm trying to do an INSERT INTO on a table tblCMActivity with columns defined as following:
(<ActTypeRef, int,>
,<Descr, varchar(30),>
,<EntryDate, datetime,>
,<EntryTime, datetime,>
,<Duration, pDec,>
,<Value, pDec,>
,<ContactRef, int,>
,<CampRef, int,>
,<UserId, pUserID,>
,<Notes, text,>)
For each row that the SELECT of r_table yields, I want to insert a row into tblCMActivity, populating the columns as follows:
ActTypeRef = 1007 (numeric literal)
Descr = "Imported from Excel" (alpha literal)
EntryDate = Today's date
EntryTime = The current time
Duration = 0 (numeric literal)
Value = 0 (numeric literal)
ContactRef = 182 (numeric literal)
CampRef = 1 (numeric literal)
UserID = Whoever is using the system
Notes = NULL
=============== =========
My query is the following:
INSERT INTO [CPU].[dbo].[tblCMActivity]
([ActTypeRef]
,[Descr]
,[EntryDate]
,[EntryTime]
,[Duration]
,[Value]
,[ContactRef]
,[CampRef]
,[UserId]
,[Notes])
SELECT
(1007,'Imported from Excel',GETDATE( ),GETTIME(),0,0 ,182,1,USER_NAM E(),NULL)
FROM [CPU].[dbo].[r_table]
-----------------------------------------------------------
When I stacked each variable on a separate line, it almost indicated that it especially didn't like the constant "Imported from Excel" - but what on earth does it want? What will satisfy it? This is all taken from examples I've found elsewhere.
I'm trying to do an INSERT INTO on a table tblCMActivity with columns defined as following:
(<ActTypeRef, int,>
,<Descr, varchar(30),>
,<EntryDate, datetime,>
,<EntryTime, datetime,>
,<Duration, pDec,>
,<Value, pDec,>
,<ContactRef, int,>
,<CampRef, int,>
,<UserId, pUserID,>
,<Notes, text,>)
For each row that the SELECT of r_table yields, I want to insert a row into tblCMActivity, populating the columns as follows:
ActTypeRef = 1007 (numeric literal)
Descr = "Imported from Excel" (alpha literal)
EntryDate = Today's date
EntryTime = The current time
Duration = 0 (numeric literal)
Value = 0 (numeric literal)
ContactRef = 182 (numeric literal)
CampRef = 1 (numeric literal)
UserID = Whoever is using the system
Notes = NULL
=============== =========
My query is the following:
INSERT INTO [CPU].[dbo].[tblCMActivity]
([ActTypeRef]
,[Descr]
,[EntryDate]
,[EntryTime]
,[Duration]
,[Value]
,[ContactRef]
,[CampRef]
,[UserId]
,[Notes])
SELECT
(1007,'Imported from Excel',GETDATE( ),GETTIME(),0,0 ,182,1,USER_NAM E(),NULL)
FROM [CPU].[dbo].[r_table]
-----------------------------------------------------------
When I stacked each variable on a separate line, it almost indicated that it especially didn't like the constant "Imported from Excel" - but what on earth does it want? What will satisfy it? This is all taken from examples I've found elsewhere.
Comment