Can't find what you're looking for? Use of one of the search websites below …
Bing Google Yahoo! Site (Default)
Control structures syntax; IF THEN ELSE, CASE, WHILE .
The IF THEN ELSE syntax in TSQL is kinda weird if you ask me … I forget them ‘all the time’, created examples below for my reference.
if 1 = 1 begin print 'true' end go
if 1 = 1 print 'true' go
if 1 = 1 begin print 'true' end else begin print 'false' end go
if 1 = 1 print 'true' else print 'false' go
if 1 = 1 begin print '1 = 1' end else if 1 = 2 begin print '1 = 2' end else if 1 = 3 begin print '1 = 3' end go
TSQL has the CASE control structure …
declare @i int, @r int set @i = 1 set @r = case @i when 1 then 1 when 2 then 2 else 0 end print @r go
while 1 = 1 print 'true' go
declare @i int set @i = 0 while @i < 10 begin print @i set @i = @i + 1 end go
Name (required)
Mail (will not be published) (required)
Website
Control Structures
Control structures syntax; IF THEN ELSE, CASE, WHILE .
IF THEN ELSE
The IF THEN ELSE syntax in TSQL is kinda weird if you ask me … I forget them ‘all the time’, created examples below for my reference.
IF THEN
IF THEN – short notation
IF THEN ELSE
IF THEN ELSE – short notation
Multiple IF THEN ELSE blocks
CASE
TSQL has the CASE control structure …
WHILE
Eternal loop
Simple WHILE loop