Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Please Provide me the Correct Syntax Of Query

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-09-02 : 00:53:03
Hello All,

Please Correct the Given below Query,
Actually I want to select date between start date and end date of another table

select * from LEV_Employee_Leaves_Detail
where Leave_Date between select Start_Date AND End_Date from CLT_Client_Month



Thanks In Advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-02 : 01:07:23
How many rows are there in CLT_Client_Month? If there is more than one row, how should it determine which row to use?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-09-02 : 01:09:29
There is only one row in this table
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-02 : 01:31:21
You could put the values into variables first and then just use the variables in the BETWEEN or:

WHERE Leave_Date >= (SELECT Start_Date FROM CLT_Client_Month) AND Leave_Date <= (SELECT END_DATE FROM CLT_Client_Month)

You could get fancier, but I'd just go with the variable approach.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -