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.
| Author |
Topic |
|
anumodhc
Starting Member
13 Posts |
Posted - 2009-03-05 : 07:35:16
|
| i want to get 3 continuous dates, then after 22 days in one year.example:-from january 1st 1,2, and 3rd jan. then after 22 days 25,26, 27 jan.like that.Please adviseAnumodH |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-05 : 07:43:39
|
[code]DECLARE @theYear SMALLINTSET @theYear = 2009-- Display the datesSELECT DATEADD(DAY, 24 * v.Number + d.Number, DATEADD(YEAR, @theYear - 1900, 0))FROM master..spt_values AS vINNER JOIN master..spt_values AS d ON d.Type = 'P' AND d.Number < 3WHERE v.Type = 'P' AND v.Number < 16[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
anumodhc
Starting Member
13 Posts |
Posted - 2009-03-05 : 08:32:45
|
| Thanks PesoHow to get the same within a date range?AnumodH |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-03-05 : 08:49:06
|
This should work incase you need a range,,DECLARE @theYear SMALLINTDECLARE @toYear SMALLINTSET @theYear = 2009SET @toYear=2010-- Display the datesselect * from (SELECT DATEADD(DAY, 24 * v.Number + d.Number, DATEADD(YEAR, @theYear - 1900, 0)) resultFROM master..spt_values AS vINNER JOIN master..spt_values AS d ON d.Type = 'P' AND d.Number < 3WHERE v.Type = 'P' --AND v.Number < 16)a where result<convert(varchar,@toYear)+'1231' |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-03-05 : 08:49:55
|
sql 2k,DECLARE @START DATETIME DECLARE @THEYEAR SMALLINTDECLARE @I SMALLINTSET @THEYEAR = 2009SET @I=1SET @START=CONVERT(DATETIME,CONVERT(VARCHAR,@THEYEAR)+'0101')PRINT @STARTWHILE (@START<CONVERT(DATETIME,CONVERT(VARCHAR,@THEYEAR)+'1231'))BEGIN IF (@I%3=0 AND @I<>0) SET @START=@START+22 ELSE SET @START=@START+1 PRINT @START SET @I=@I+1END |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-03-05 : 09:17:00
|
quote: Originally posted by anumodhc How to get the same within a date range?
What do you mean by a date range?1. The 1-2-3..25-26-27 sequence starts at an arbitrary date and ends at an arbitrary date?2. The 1-2-3..25-26-27 always starts at january 1st but you want an arbitrary subset date range from that? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|