|
Email lists >
aspnet at aspadvice.com >
[aspnet] RE: SQL GURU: IN operator with Case Statement >
[aspnet] RE: SQL GURU: IN operator with Case Statement
[aspnet] RE: SQL GURU: IN operator with Case Statement
This post if a part of this thread
|
2008-06-10 13:15:14 |
|
|
RE: SQL GURU: IN operator with Case Statement
|
|
|
I modified my routine to use a soup of routines.
I like Keith's suggestion so I used it to populate tbl. I didn't use it to inner join cuz I have several other tables in my join operations. Can't denormalize. Not my DB.
Then, I modified the where clause to do a sub-select from tbl
IF parm <> 0 -- We got a parm passed in so use just it...
INSERT INTO tbl (intCodes) select 123 INSERT INTO tbl (intCodes) select 456 INSERT INTO tbl (intCodes) select 789
END
Then,
WHERE intField IN (SELECT intCodes FROM tbl)
From: john jwarner.com To: aspnet aspadvice.com Subject: [aspnet] RE: SQL GURU: IN operator with Case Statement Date: Tue, 10 Jun 2008 13:05:12 -0400
Keith, depending on the size of tblBlah your method would offer the fastest result set.
John Warner
Not necessarily (though I like Penton's solution).
CREATE PROC myProc parm int = 0 -- Default parm to 0 if nothing is passed in
AS
BEGIN
problem with this is, if the user submits a parm, then it has to be used in the where clause. I added a value of "0" with text "-All-" in the page drop down in the first index before the 3 hard-coded codes. So, that's why I'm checking for parm = 0.
Date: Tue, 10 Jun 2008 11:56:38 -0400 From: terri.morton gmail.com To: aspnet aspadvice.com Subject: [aspnet] RE: SQL GURU: IN operator with Case Statement
But you could do a LEFT OUTER JOIN:
declare tbl TABLE( intCodes INT) INSERT tbl select 123INSERT tbl select 456INSERT tbl select 789 SELECT blah, blahFROM tblBlahLEFT OUTER JOIN tbl ON tblBlah.intField = tbl.intCodesWHERE tbl.intcodes IS NOT NULL OR param = 0 FWIW, I always recommend these great articles by Erland Sommarskog on Arrays and Lists in SQL Server: http://www.sommarskog.se/arrays-in-sql-2005.html http://www.sommarskog.se/arrays-in-sql-2000.html
On Tue, Jun 10, 2008 at 11:45 AM, Tim Curtin < tjc_tek  hotmail.co m">tjc_tek hotmail.com> wrote:
--- List Settings --- http://aspadvice.com/lists/
Enjoy 5 GB of free, password-protected online storage. Get Windows Live SkyDrive. --- List Settings --- http://aspadvice.com/lists/
Notice of Confidentiality
This transmission contains information that may be confidential. It has been prepared for the sole and exclusive use of the intended recipient and on the basis agreed with that person. If you are not the intended recipient of the message (or authorized to receive it for the intended recipient), you should notify us immediately; you should delete it from your system and may not disclose its contents to anyone else.
This e-mail has come to you from Watson Wyatt & Company. --- List Settings --- http://aspadvice.com/lists/
--- List Settings --- http://aspadvice.com/lists/
Enjoy 5 GB of free, password-protected online storage. Get Windows Live SkyDrive.
--- List Settings ---
http://aspadvice.com/lists/
|
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|