SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 What is wrong with this statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gaby_58
Starting Member

8 Posts

Posted - 06/21/2012 :  11:15:12  Show Profile  Reply with Quote
Hi all,

I have this SQL statement and gives an error like this
Incorrect syntax near '6335'
cmdS2 = new SqlCommand("SELECT TOP 1 SupplierId, Supplier,"
+ " SUM(TotalValue) FROM view_test WHERE YEAR(dDate)='"
+ pRefYear.ToString() + "' AND " + strR +
"Id IN(" + strId
+ ")AND SupplierId <> '"
+ strSupplierId[0]
+ "AND SupplierId <> '6335'"
+ "GROUP BY SupplierId, Supplier ORDER BY SUM(TotalValue) DESC", conS2);

Thanks for any info

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 06/21/2012 :  11:48:16  Show Profile  Reply with Quote
Remove the single quote on the line indicated below:
cmdS2 = new SqlCommand("SELECT TOP 1 SupplierId, Supplier,"
+ " SUM(TotalValue) FROM view_test WHERE YEAR(dDate)='"
+ pRefYear.ToString() + "' AND " + strR +
"Id IN(" + strId
+ ")AND SupplierId <> '" -- <== Remove the single quote shown in red
+ strSupplierId[0]
+ "AND SupplierId <> '6335'"
+ "GROUP BY SupplierId, Supplier ORDER BY SUM(TotalValue) DESC", conS2);
Also, put spaces so that there is a space between the supplierId and the AND that follows it; similarly, before GROUP BY etc.
Go to Top of Page

gaby_58
Starting Member

8 Posts

Posted - 06/21/2012 :  11:59:19  Show Profile  Reply with Quote
Thanks a lot, it worked..
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000