Hi
CREATE TABLE #T
(
amount INT,
[month] INT,
[year]INT
)
INSERT INTO #T VALUES (10,4,2006)
INSERT INTO #T VALUES (20,5,2006)
INSERT INTO #T VALUES (30,6,2006)
INSERT INTO #T VALUES (40,1,2007)
INSERT INTO #T VALUES (10,2,2007)
INSERT INTO #T VALUES (40,1,2008)
INSERT INTO #T VALUES (10,2,2008)
SELECT * FROM #T
WHERE CAST(RTRIM([year]*10000+[month]*100+1) AS DATETIME) BETWEEN '20060401'
AND '20070101'
[quoted text, click to view] "hon123456" <peterhon321@yahoo.com.hk> wrote in message
news:1158641294.928689.221630@m7g2000cwm.googlegroups.com...
> Dear all,
>
> I got a table like this:
>
>
> month year
> amount
> 4 2006
> 10
> 5 2006
> 20
> 6 2006
> 30
> 4 2006
> 40
> 1 2007
> 10
> 2 2007
> 20
> 3 2007
> 30
>
> Now I want to select the record between the range 04/2006 and
> 03/2007, how can do that?
>
> I try : select * where convert(varchar(2),a.month1) + '/' +
> convert(varchar(4), a.year1) < '03/2007'
>
> and where convert(varchar(2),a.month1) + '/' + convert(varchar(4),
> a.year1) > '4/2006'
>
> But it does not work. Please help.
>
> Thanks
>