Wednesday, April 13, 2011

SQL If and Case statements

If Statements example:


declare @num int
set @num = 4

select @num

if @num = 3
begin
select 'yay...its 3'
end
else
begin
select 'boo...no 3'
end





Case Statements example



use AdventureWorks
go

select FirstName, LastName,
case EmailPromotion
when 1 then 'EmailPromo'
when 2 then 'TextPromo'
else 'Leave Me Alone'
end as promo
from Person.Contact


No comments:

Post a Comment