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 |
legacyvbc
Starting Member
37 Posts |
Posted - 2007-09-27 : 22:34:58
|
I have a calendar table with the following fieldsDate,EOW(bit),EOM(bit),EOQ(bit),EOY(bit)I am trying to write a procedure that takes an input of:@rebal (which will be either 1,4,12,52)and return all dates that are true for either EOW,EOM,EOQ etc.but I can't get it to work. My code is below although I have tried several other variations.Essentially if @rebal = 1 then return all Dates with EOY=1if @rebal=4 then return all Dates with EOQ=1 etc.Any help is greatly appreciated.ThanksEXAMPLEDECLARE @rebal tinyintSET @rebal=1SELECT a.dt, dt = CASE WHEN @rebal = 1 THEN SELECT dt from dbo.calendar where EOY=1 WHEN @rebal = 4 THEN SELECT dt from dbo.calendar where EOQ=1ENDFROM dbo.calendar awhere a.dt >= '03/31/2000' AND a.dt <= '12/31/2007'W |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-27 : 22:46:30
|
[code]SELECT a.dtFROM dbo.calendar aWHERE a.dt >= '03/31/2000' AND a.dt <= '12/31/2007'AND ( (@rebal = 1 AND EOY = 1) OR (@rebal = 4 AND EOQ = 1) )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-28 : 02:37:55
|
Also make sure to exspress dates in YYYYMMDD formatMadhivananFailing to plan is Planning to fail |
 |
|
legacyvbc
Starting Member
37 Posts |
Posted - 2007-09-28 : 11:02:25
|
Why do the dates need to be in that format? |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-28 : 11:05:20
|
to avoid possible confusion of DD/MM/YYYY or MM/DD/YYYY which will result in date conversion error KH[spoiler]Time is always against us[/spoiler] |
 |
|
legacyvbc
Starting Member
37 Posts |
Posted - 2007-09-28 : 11:06:56
|
Also, thanks for the help. The code works perfect! |
 |
|
|
|
|
|
|