By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,962 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,962 IT Pros & Developers. It's quick & easy.

SQL Select Statement Syntax

P: 6
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_NAME(),N ULL)

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.
Mar 11 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
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_NAME(),N ULL)

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.
No need to enclosed the columns in a parenthesis. Here's the complete INSERT INTO syntax.

-- CK
Mar 11 '08 #2

P: 6
No need to enclosed the columns in a parenthesis. Here's the complete INSERT INTO syntax.

-- CK

Yes, taking out the SELECT parentheses helped greatly.

Thank you!
Mar 11 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.