Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE Vs IF.Else

Author  Topic 

pravin14u
Posting Yak Master

246 Posts

Posted - 2008-03-13 : 04:07:27
The following is a condition that I need to implement

IF @CustomerId = '-1'
BEGIN
SET @whereClause = @whereClause
END
ELSE
BEGIN
SET @whereClause = @whereClause +' AND (Customer_id =' + '''' + @CustomerId + ''') '
END

Should I use a case statement here or leave it to IF ELSE... which will give me optimal performance?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 04:10:49
IF @CustomerID <> '-1'
SET @whereClause = @whereClause +' AND (Customer_id = ' + '''' + @CustomerId + ''') '

will be enough



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -