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 2008 Forums
 Transact-SQL (2008)
 month number and year number where condition betwe

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2012-11-25 : 17:25:22
Is it possible to between dates of whole month, if i pass just month number and year.

If i pass 10 & 2012

Can this be done:

where reg_dt_tm BETWEEN to_date('10/01/2012', 'MM/DD/YYYY') AND to_date('10/31/2012',
'MM/DD/YYYY')

or

If i pass 11 & 2012

where reg_dt_tm BETWEEN to_date('11/01/2012', 'MM/DD/YYYY') AND to_date('11/30/2012',
'MM/DD/YYYY')


Thanks for the helpful info.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-25 : 17:42:17
WHERE reg_dt >= DATEADD (month,@month-1, DATEADD(year,@year-1900,'19000101')) and reg_dt < DATEADD (month,@month, DATEADD(year,@year-1900,'19000101))

There is no to_date in sql server.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -