Counter of Festivals

Ashok Blog for SQL Learners and Beginners and Experts

Monday 13 January 2014

IF ELSE BLOG IN SQL

Blue print of IF ELSE:

IF Boolean_expression
     { sql_statement | statement_block }
[ ELSE
     { sql_statement | statement_block } ]

Original blue print:

IF (condition)
BEGIN
.........................................
END

ELSE
.........................................


Sample 1:

Declare @selecdate datetime

IF (Select top 1 salarydate from employee where empid= 'EP00001')  is not null

BEGIN

select top 1 @selecdate= salarydate from employee where empid= 'EP00001'

END

ELSE

Select top 1 @selecdate= date from salarypayslip where empid= 'EP00001' and month='Jan'

select @selecdate

No comments:

Post a Comment