Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This query looks ok to me...

Status
Not open for further replies.

DroopyA

Programmer
Aug 5, 2003
52
0
0
US
I'm getting a "Incorrect Syntax" error when I execute this SQL Statement. What is wrong?

&quot;SELECT * FROM Permit WHERE Prefix = 'Template' AND Auth_DT <= #2/28/2004 12:23:25 PM#&quot;

Permit is the table
Prefix is nvarchar
Auth_DT is datetime
 
Can you run it in SQL Server's Query Analyzer in this way:

SELECT *
FROM Permit
WHERE Prefix = 'Template' AND Auth_DT <= 2/28/2004 12:23:25 PM

That might give more information about where the syntax error exists.

Or it might be an issue with recognizing the datetime format, so can you try it (in your application) as:

&quot;SELECT * FROM Permit WHERE Prefix = 'Template' AND Auth_DT <= #2004-02-28 12:23:25 PM#&quot;

-SQLBill
 
I had already posted and hadn't seen your addition. No, the # symbol is NOT used in SQL Server. But I have seen where it is used by some apps that pass a query to SQL Server.

You could try taking that symbol out.

-SQLBill
 
OK, it says

Incorrect syntax near '12'.


So it doesn't like the Time... any ideas why?

&quot;WHERE Auth_DT <= 2/28/2004&quot; works but &quot;WHERE Auth_DT <= #2/28/2004#&quot; does not

Thanks for the help. I'm kind of in a hurry with this as I have many more bugs to work out. This one just has me stumped.
 
Sorry, I forgot to add. If I keep the time in, I get the Syntax error. Even if I don't use &quot;#&quot;.

&quot;SELECT * FROM Permit WHERE Prefix = &quot;Template&quot; AND Auth_DT <= 2/28/2004 12:23:25 PM&quot;

Does not work either.
 
Ok... One last question. It seems to take

SELECT * FROM Permit WHERE Prefix = 'Template' AND Auth_DT <= '2/28/2004 12:23:25 PM'


Why would the date and time be put in quotation marks? Is it because of the space between the date and time?
 
Try this:

&quot;SELECT * FROM Permit WHERE Prefix = 'Template' AND Auth_DT <= '2/28/2004 12:23:25 PM'&quot;

The single quotes will group the date/time value and should return the results you want.

Hope this helps.

Glen Appleton

VB.Net student.
 
That was exactly it. Thanks alot. You've been a huge help to me these past couple of months.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top