473,766 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Select Statement Syntax

6 New Member
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.
Mar 11 '08 #1
2 2022
ck9663
2,878 Recognized Expert Specialist
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.
No need to enclosed the columns in a parenthesis. Here's the complete INSERT INTO syntax.

-- CK
Mar 11 '08 #2
HughManity
6 New Member
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

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

Similar topics

2
20534
by: Omavlana | last post by:
Hi, I want to create a temporary table and store the logdetails from a.logdetail column. select a.logdetail , b.shmacno case when b.shmacno is null then select cast(substring(a.logdetail,1,charindex('·',a.logdetail)-1) as char(2)) as ShmCoy,
1
11344
by: John Hall | last post by:
We need to read a SQL database containing a mix of English words and Chinese Characters. We think we need to use the N'xxxx' to read the Unicode. We have one place where the SELECT statement works fine. Here is that statement: dim objCmdCategories as new SQLDataAdapter ("select distinct N'product_category' from " & _ "tblproducts where product_status=1 order by product_category", objConn) However, we can't seem to get another SELECT...
4
6949
by: Elroyskimms | last post by:
Using SQL 2000... tblCustomer: CustomerID int CompanyName varchar(20) HasRetailStores bit HasWholesaleStores bit HasOtherStores bit tblInvoiceMessages:
17
5028
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
15
2742
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If you want to do a Left Outer Join, support nested functions, and a nested conditional clause, you'd...
4
2255
by: 001 | last post by:
Hello, The select statement needs only 1 second to complete the query. But the update statement spends 30 minutes. Why? SELECT STATEMENT: declare @IDate smalldatetime select @IDate=col001 from USDay select * from USDay A
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
4
1941
by: Jean-Claude | last post by:
Hi, which is the faster query ? (of course, in my case the real queries are more complex) 1/ select * from file1 a join file2 b on b.key=a.key where b.data=123 and b.name='TEST'
25
4344
by: CJM | last post by:
I'm getting a syntax error with a Select Case statement: Select Case CSng(rs.fields("Field1")) Case 0 Response.Write "Test1" Case Is < 0 <<< Syntax Error Response.Write "Test2" Case Is > 0 <<< Syntax Error Response.Write "Test3" End Select
2
5177
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. -------------------------------------------------------- SELECT b.ISBN, b.Title, b.SmallImage, f.idForSale, count(f.idForSale) FROM books b, forsale f
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.