Q7.2: How to implement if-then-else in a select clause
If you need to implement the following condition in a select
clause:
if @val = 'small' then
print 'petit'
else
print 'grand'
fi
do the following:
select isnull(substring('petit', charindex('small', @val), 255), 'grand')
To test it out, try the following T-SQL:
declare @val char(20)
select @val = 'grand'
select isnull(substring('petit', charindex('small', @val), 255), 'grand')