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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 using a case with a set

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-02-25 : 09:29:13
hi, can I use a case or if with a set command ?


declare @Date2 datetime

case when day(getdate()) <20 THEN
SET @Date2 = DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
ELSE
SET @Date2= getdate()
END

SELECT @Date2

This doesn't work, is there a similar way ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-25 : 09:33:10
SELECT @Date2 = CASE WHEN day(getdate()) <20 THEN DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)) ELSE getdate() END

SELECT @Date2



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-25 : 09:33:31
[code]declare @Date2 datetime

SET @Date2 =case when day(getdate()) <20 THEN DATEADD(dd,18,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
ELSE getdate()
END

SELECT @Date2[/code]
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-02-25 : 09:35:57
thank you.
Go to Top of Page
   

- Advertisement -