Wednesday, April 13, 2011

If and Case Statements

declare @num int
set @num =4
declare @salespersonid int

select @num

if @num = 3
begin
 set @salespersonid = (select top 1 Sales.SalesPerson.SalesPersonID from Sales.SalesPerson)
end
else if @num = 4
begin
 select 'boo...no 3'
end
else
begin
 select 'nun of the above'
end

use AdventureWorks
select FirstName, LastName,
case emailpromotion
 when 1 then 'Email Promo'
 when 2 then 'Text Promo'
 else 'Leave Me Alone'
end promo
from person.contact

No comments:

Post a Comment