Sunday, February 19, 2012

I need help performing a date query where the output is all related records to one specific date

Hi Everybody,

I need help with a query where the output is all records related to one specific date. Like take for ex. all records which have been entered on 5/26/07. I would really appreciate the help. Thanks in advance. . .

I've pasted the code which I've been using but just gives me a reserved error 3646.

SELECT Escal_Tracker.Escal_Type, Escal_Tracker.Cross_func, Escal_Tracker.cas_no, Escal_Tracker.Inc_no, Escal_Tracker.esc_com, Escal_Tracker.nt_login, Escal_Tracker.Date
FROM Escal_Tracker
WHERE date = '5/26/07';

Regards,

Inspired_One

Hi inspired_one,

Move the thread from Visual Basic Forum in order to get better answers, since this issue is related to Transact-SQL.
Thanks for your understanding!

|||

Your code is 'mostly' ok. I recommend using the ISO date format which for SQL Server, is unabiguous. Also, if any of the Date field values include a time component, they will not match. The best way to accomplish a filter criteria for a complete day is to bracket all values between midnight the desired date, and just before midnight the next date. Also when you use reserved words as your table or column names, you MUST then always enclose them in square brackets to let the server know that you made a mistake and now must type extra keystrokes to compensate. ( [Date] is a reserved word.) Refer to Books Online, Topic: 'Reserved Words'

Perhaps this will work for you...

Code Snippet


SELECT
e.Escal_Type,
e.Cross_func,
e.cas_no,
e.Inc_no,
e.esc_com,
e.nt_login,
e.[Date]
FROM Escal_Tracker e
WHERE ( e.[Date] >= '2007/05/26'
AND e.[Date] < '2007/05/27'

|||

Arnie,

Thanks a lot for the help bro. that actually led me to the answer to this problem which was .

SELECT
e.Escal_Type,
e.Cross_func,
e.cas_no,
e.Inc_no,
e.esc_com,
e.nt_login,
e.[Date]
FROM Escal_Tracker e
WHERE ( e.[Date] >= # " & varfirstdate & " # AND e.[Date] < # " & varseconddate & " #

The difference is I'm using vba variables for this code. . .

Regards,

Inspired one

No comments:

Post a Comment