Platinum Partner
database,sql server

Case And If Else Statement In Sql Server



DECLARE @MyVal INT

DECLARE @OUTPUTValues VARCHAR(200)
SET @MyVal = 1

SELECT @OUTPUTValues =
(
CASE  @MyVal
        WHEN 1 THEN 'test1'
        WHEN 2 THEN 'test2'
        WHEN 3 THEN 'test3'
        ELSE 'New'
END
)

PRINT @OUTPUTValues

SET @TestVal = 5

IF @MyVal= 1
SET @OUTPUTValues= '1'
ELSE IF @MyVal= 2
SET @OUTPUTValues= '2'
ELSE IF @MyVal= 3
SET @OUTPUTValues= '3'
ELSE
SET @OUTPUTValues= @MyVal

PRINT @OUTPUTValues



{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}