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 |
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2008-07-28 : 04:26:26
|
| Is it possible to change the following?DATEADD(WEEK, 0, DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0)) AS FirstdayofthisweekTo:DATEADD(@Type1, @Value1, DATEADD(@Type2,DATEDIFF(@Type3, @Value2, GETDATE()), @Value3)) AS mydateIf it's not possible to use variables directly how can they be used indirectly? My idea is to enable the customer to change from day, week, quarter, year etc without having lots of Case statements. Plus I am trying to learn. Thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-28 : 04:34:42
|
No, you can't.However you can use a CASE statementsSELECT @Type1 WHEN 'Week' THEN DATEIFF(Week, @p1, @p2) WHEN 'Month' THEN DATEIFF(Month, @p1, @p2)END E 12°55'05.25"N 56°04'39.16" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-28 : 04:39:54
|
quote: without having lots of Case statements
Actually, you only need one CASE statement as Peso has demonstrate KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|