|
-
Dec 19th, 2008, 01:11 PM
#1
Thread Starter
Frenzied Member
[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?
-
Dec 19th, 2008, 01:23 PM
#2
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
-
Dec 19th, 2008, 01:33 PM
#3
Thread Starter
Frenzied Member
Re: [RESOLVED] SQL Case Performance Q
thanks, is that a performance increase as well as an easier way to write it?
-
Dec 19th, 2008, 01:38 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|