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 2000 Forums
 SQL Server Development (2000)
 adding month colomn and year coloumn

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2009-04-02 : 23:35:07
i have a table where the customer date is stored
as month colomn and year colomn

i mean month march is 3 april 4 and so on

customerid customername month year
1 john 3 2007
3 james 5 2007
5 jane 1 2008
7 jack 4 2008

if i want the information between the dates
'03/01/2007' and '04/01/2008'

how can i write the select query using the month and year coloumn



robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-04-02 : 23:58:06
SELECT * FROM myTable WHERE CONVERT(datetime, CAST([month] as varchar) + '/01/' + CAST([year] as varchar), 101) BETWEEN '03/01/2007' AND '04/01/2008'

Warning: not tested, and the convert function may bomb on months less than 10.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-03 : 03:26:59
Also refer
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=122902

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -