[RESOLVED] SQL Case Performance Q
If I would like to check multiple fields in my record would it be wise to use a case or is there a better method? Basically I want to check if multiple fields have a 1, if they do I am going to display 'yes' in one field.
So it would kinda look like this
Select ID, Sub_ID, Name,
CASE
WHEN Check1 = 1 THEN 'Yes'
WHEN Check2 = 1 THEN 'Yes'
WHEN Check3 = 2 THEN 'Yes'
--etc...
ELSE 'No'
END As HasACheck
FROM Table1
Is there a better way that I should be doing this?
Re: SQL Case Performance Q
Code:
Select ID, Sub_ID, Name,
CASE WHEN Check1 = 1 OR Check2 = 1 OR Check3 = 2 THEN 'Yes'
ELSE 'No'
END As HasACheck
FROM Table1
Re: [RESOLVED] SQL Case Performance Q
thanks, is that a performance increase as well as an easier way to write it?
Re: [RESOLVED] SQL Case Performance Q
I'm not sure about performance increase... but surely it is easier way to write it.. you are not repeating same thing this way.
For performance, just time the two queries in the query analyser and you should come to know. As far as I know, both should perform equally well.