Click here to Skip to main content
15,902,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Team,

I got confused to get the date in Single Quotes.I know that i forgot to put the single quotes to get the date .Please kindly guide me
I have the query as follow:
select count(ID) as count from Customerloandata with (nolock) where createdby = 4 AND isnull(QCPROCESSED,0) = 0 AND isnull(QCTOVERIFY,0) = 1 and isnull(deleted,0) = 0 AND createdon >=2014-01-01 00:00:00  and createdon<=2014-04-01 00:00:00 


I am getting the error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '00'.


Thanks
Harshal
Posted

Try this:
SQL
select count(ID) as count from Customerloandata with (nolock) where createdby = 4 AND isnull(QCPROCESSED,0) = 0 AND isnull(QCTOVERIFY,0) = 1 and isnull(deleted,0) = 0 AND createdon >='2014-01-01 00:00:00'  and createdon<='2014-04-01 00:00:00' 
 
Share this answer
 
Comments
[no name] 1-Apr-14 8:22am    
it should be like thisstring query = "select count(ID) as count from Customerloandata with (nolock) where createdby = 4 AND isnull(QCPROCESSED,0) = 0 AND isnull(QCTOVERIFY,0) = 1 and isnull(deleted,0) = 0 AND createdon >='" + qcallocation.FromDate.ObjectToDBDateTime() + "' and createdon<='" + qcallocation.ToDate.ObjectToDBDateTime() + "' ";
[no name] 1-Apr-14 8:22am    
Sorry Buddy,its my mistake i wrote the wrong Query..
Thanks for your reply
Tom Marvolo Riddle 1-Apr-14 8:23am    
you're welcome
you are missing quotes in datetime string.

SQL
select count(ID) as count from Customerloandata with (nolock) where createdby = 4 AND isnull(QCPROCESSED,0) = 0 AND isnull(QCTOVERIFY,0) = 1 and isnull(deleted,0) = 0 AND createdon >='2014-01-01 00:00:00'  and createdon<='2014-04-01 00:00:00' 
 
Share this answer
 
Comments
[no name] 1-Apr-14 8:21am    
it should be like this .
string query = "select count(ID) as count from Customerloandata with (nolock) where createdby = 4 AND isnull(QCPROCESSED,0) = 0 AND isnull(QCTOVERIFY,0) = 1 and isnull(deleted,0) = 0 AND createdon >='" + qcallocation.FromDate.ObjectToDBDateTime() + "' and createdon<='" + qcallocation.ToDate.ObjectToDBDateTime() + "' ";
[no name] 1-Apr-14 8:23am    
Sorry Buddy,its my mistake i wrote the wrong Query..
Thanks for your reply
Schatak 1-Apr-14 8:24am    
No probs :)
Schatak 1-Apr-14 8:23am    
you want to have inline query in code behind?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900