-
Solved: nested loop on sql statement
Ok guys I am trying get some info by dates and having a little trouble with my statement, i basically want to change the year and month i am looking at, but leave the day as the first
ie 2008-01-01, 2008-02-01....2010-07-01, 2010-08-01
i think i am doing something wrong in converting to a date and i am not actually sure my loops will work, first time looking at sql loops forgive me.
here is my code, any help?
declare @yr int
declare @mth int
set @yr = 2007
set @mth = 0
while @yr<=2010
begin
while @mth<=12
begin
SELECTcount(case when expirydate <= @yr +'-'+ @mth +'-01' then linecode end)as [ended],
count(case when deliverydate <=@yr +'-'+ @mth +'-01' then linecode end)as [current welds],
count(case when deliverydate <=@yr +'-'+ @mth +'-01' then linecode end)
-count(case when expirydate <=@yr +'-'+ @mth +'-01' then linecode end)as [Total]
FROM sometable
where code ='xxx'
end
end
is this also possible without creating a table?
Last edited by Gtrain; 08-03-2010 at 11:03 PM.
-
had to convert to varchar,
this can be closed Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules