Click here to Skip to main content
15,614,138 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have to compare time attributes of two tables and query is like
select s.sid
from sal s, prod p
and p.beginDate<
and p.endDate>

i want to know, how it will be evaluated.mean, is it same to following query

select s.sid
from sal s, prod p
and p.beginDate<2008-01-10'
and p.endDate>'2008-01-10'

Use Query analyzer of SQL Server to find the query cost and performance.
Share this answer
s_aslam98 17-Dec-10 14:10pm    
okay, i check it.but, is it theoratically right
Yes, it should do the same thing, but you could have determined that yourself by simply running the two different query versions in SQL Server Management Studio Express...

Share this answer
there's two way to compare Date Time types, but i see that you need the Date and not the time comparation right?

well, if you need the time Use this function CONVERT(DataType,Value,#)
here an example
SELECT CONVERT(varchar(11),fecha_de_Emision,113),
       CONVERT(varchar(11),fecha_de_Emision,112) ,
       CONVERT(varchar(11),fecha_de_Emision,110) ,
FROM TableOfSomeDates WHERE Date1 >=Date2

the result is a several dates in differents formats..

remember if you want comparate Date be sure that the date is in the correct format like MM/DD/YY OR MM/DD/YYYY OR MM/DD/YYYY HH:MM:SS

the simple way to do this is to use the CONVERT function

CONVERT(varchar(11),fecha_de_Emision,110) the result is '11-09-2011' (avoid the time, leave only the Date)
then you can compare with your DateTime

[Edited]Code is wrapped in "pre" tag[/Edited]
Share this answer
RaviRanjanKr 10-Nov-11 6:55am    
A Suggestion :- Always wrap your code in "pre" tag to give better readability to user.
Rene Bustos 23-Nov-11 10:54am    
ok. thanks Ravi!

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