Wednesday, April 13, 2011

Advanced Relational Database */ If & Case Statements */

If and Else If Statement
use AdventureWorks

declare @num int
set @num = 3
declare @salespersonid int

select @num

if @num = 2
begin
 set @salespersonid = (select top 1 Sales.SalesPerson.SalesPersonID from Sales.SalesPerson)
end
else if @num = 4
begin
 select 'you suck'
end
else
begin
 select 'nun of the above'
end
Case Statement
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

Classes

Programming II

Advanced Relational Database

Followers