else If in tsql
I mu开发者_如何学Pythonst update table, and I can't use else if in tsql. Is it exists?
Status =
(
CASE
WHEN
(Status in (0))
THEN
0
ELSE IF Status in (1)
THEN
7
ELSE
Status
END
The CASE WHEN syntax does support multiple conditions:
Status = CASE WHEN Status = 0 THEN 0
WHEN Status = 1 THEN 7
ELSE Status
END
Since you are comparing the same field for equality in both cases, you can use the shorter notation:
Status = CASE Status WHEN 0 THEN 0
WHEN 1 THEN 7
ELSE Status
END
Use again CASE WHEN:
Status = CASE WHEN Status in (0)
THEN 0
ELSE CASE WHEN Status in (1)
THEN 7
ELSE Status
END
END
or
Status = CASE WHEN Status in (0) THEN 0
WHEN Status in (1) THEN 7
ELSE Status
END
You should use the following syntax:
Status =
(CASE WHEN (Status in (0)) THEN 0
WHEN (Status in (1)) THEN 7
ELSE Status
END)
try
Status =
(
CASE
WHEN
(Status in (0))
THEN
0
WHEN Status in (1)
THEN
7
ELSE
Status
END
Yes, you can use IF statements in SQL. Check this
Declare @x int
set @x = 29
if @x = 29 print 'The number is 29'
if @x = 30 print 'The number is 30'
精彩评论