Respected sir,
I need a query to retrieve all the week ends date of any given year.
ex
if year is 2006 from jan 01 2006 to dec 31 2006
then
6/1/2006 is saturday,7/1/2006 is sunday...etc upto last weekend day of 2006
if any one can help it
please do it
thanking you
sandeep patil
You can also use a tally table or number table to achieve this. I am using query to generate the number ranges 0 to 355declare @.year int
select @.year = 2006
select dte, datename(weekday, dte)
from
(
select dateadd(day, n, dateadd(year, @.year - 1900, 0)) as dte
from
(
select (a * 100) + (b * 10) + c as n
from
(
select 0 as a union select 1 union select 2 union select 3 union select 4 --union
--select 5 union select 6 union select 7 union select 8 union select 9
) a
cross join
(
select 0 as b union select 1 union select 2 union select 3 union select 4 union
select 5 union select 6 union select 7 union select 8 union select 9
) b
cross join
(
select 0 as c union select 1 union select 2 union select 3 union select 4 union
select 5 union select 6 union select 7 union select 8 union select 9
) c
) d
where n < datediff(day, dateadd(year, @.year - 1900, 0), dateadd(year, @.year - 1900 + 1, 0))
) f
where datepart(weekday, dte) in (1, 7)
order by dte|||
Hello tan,
Thank you very much for the help.
As i am new to this field i will be asking more no of quries plz help me.
Thanking you sandeep patil
No comments:
Post a Comment