Can I use an IF inside a Select with SQL Server?

kkbenj
kkbenj used Ask the Experts™
on
Ideally, I'd like the column displayed if the IF is true, otherwise display a blank.

Select if(charindex('code',fieldname)>0,fieldname,'')
...

Open in new window


How can I do this type of select in SQL Server?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
Yes, like this:
Select case when charindex('code',fieldname)>0 then fieldname else '' end

Open in new window

Author

Commented:
Fantastic.  And thank you for the rapid response!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial