x

Sql 2005 Case Clause Query

DECLARE @Status INT SET @Status = 1 -- (can be 0,1,2)

SELECT * FROM Members WHERE Mem_Number in ( SELECT MemberID FROM GroupMember WHERE GroupId = @GpId AND IsCardNumber = 0) AND CASE WHEN @Status < 2 THEN Mem_Archeived = @Status ELSE 1=1 END

--In this If @status variable is less than 2 then Mem_Archeived column is considered otherwise not.


Any help on this would be great!

Thanks Kapil

more ▼

asked Feb 25, 2010 at 10:31 AM in Default

avatar image

Kapil Agarwal
11 1 1 3

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

I think that should work

DECLARE @Status INT SET @Status = 1 -- (can be 0,1,2)

SELECT * FROM Members WHERE Mem_Number in ( SELECT MemberID FROM GroupMember WHERE GroupId = @GpId AND IsCardNumber = 0) AND Mem_Archeived = CASE WHEN @Status < 2 THEN @Status ELSE Mem_Archeived END END

Scott

more ▼

answered Feb 25, 2010 at 11:34 AM

avatar image

Scott Fisher
46 2 1

(comments are locked)
10|1200 characters needed characters left

-- Try this

DECLARE @Status INT SET @Status = 1 -- (can be 0,1,2)

SELECT * FROM Members WHERE Mem_Number in ( SELECT MemberID
FROM GroupMember
WHERE GroupId = @GpId
AND IsCardNumber = 0) AND (Mem_Archeived = @Status OR @Status < 2)

more ▼

answered Mar 17, 2010 at 03:01 AM

avatar image

Aditya Kumar
1

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1066
x426

asked: Feb 25, 2010 at 10:31 AM

Seen: 1559 times

Last Updated: Feb 25, 2010 at 10:34 AM

Copyright 2016 Redgate Software. Privacy Policy