karthik parcha

karthik parcha

  • NA
  • 153
  • 93.1k

HOw to write cases in SQLSERVER

Nov 11 2011 7:43 AM
HI this ismy issue please help me
Contract Signing Date + 1 year - 1 day.
(Example if the contract signed was on 2/3/2011 then it would be active through 2/2/2012.Then i have to show textmarketing status active otherwise if the contract is not in between the dates then inactive please help me
IF text marketing status is active i have to show expiration date
inactive i have to expiration date NULL
I have written alomost but not getting result
SIGNING_DATE <= EXPIRATION_DATE(

Explanation:FIrst i have updated the Expiration date column by siging date
UPDATE T
SET T.EXPIRATION_DATE=(DATEADD(DAY,-1,(DATEADD(YEAR,1,T.SIGNING_DATE))))//Contract Signing Date + 1 year - 1 day.

//Iam checking the condition with expiration can u plesae write in one single update statement if possible

UPDATE #TEMP_SB  SET TEXT_MARKETING_STATUS =
(CASE
WHEN SIGNING_DATE <= EXPIRATION_DATE THEN 'ACTIVE'
ELSE 'INACTIVE'
END)
UPDATE #TEMP_SB set EXPIRATION_DATE=NULL WHERE TEXT_MARKETING_STATUS='INACTIVE'
SELECT * FROM #TEMP_SB



Answers (2)