The thing to be careful of here is ... do you mean can I use a CASE
statement and an IF
statement together? For example in a Stored Procedure?
The answer to that is "Yes", for example this sql is perfectly valid (if meaningless)
DECLARE @temp int
DECLARE @dt date
DECLARE @res VARCHAR(10)
SET @temp = 3
SET @dt = '03-JAN-2015'
IF @temp = 3
BEGIN
set @res = CASE WHEN @dt = '01-JAN-2015'
THEN 'Bank Holiday' ELSE 'Go to work' END
PRINT @res
END
CASE can also be used as a
clause in a sql select statement for example
SELECT CASE WHEN DATENAME(dw, recDate) = 'Friday' THEN 'Leave early'
WHEN DATENAME(dw, recDate) = 'Monday' THEN 'Groan'
ELSE 'Go to work' END
FROM CP1
However, the IF statement cannot be used in the same way, so if the question is can I use a CASE clause and an IF clause in the same statement the answer is "No". For example the following SQL will generate an error
SELECT IF DAY(recDate = 6) 'Leave early' END FROM CP1
It is possible to use IIF in a where clause - see this
blog[
^] but on the whole I would personally stick to CASE