June 21, 2007 at 3:08 pm
Hi,
Is there a way (through case or if statements i assume) to select rows from a table depending on a parameters value?
i.e.
@customerID int
if customerID = (certainValue)
select * from Table where customerID = @customerID
else
select * from table
Thanks for your time
Lee
June 21, 2007 at 3:13 pm
select * from Table
where customerID = @customerID OR @customerID IS NULL
_____________
Code for TallyGenerator
June 22, 2007 at 8:50 am
SELECT * FROM myTable
WHERE customerID = CASE
WHEN @customerID = myValue THEN myValue
ELSE customerID
END
Terri
To speak algebraically, Mr. M. is execrable, but Mr. C. is
(x+1)-ecrable.
Edgar Allan Poe
[Discussing fellow writers Cornelius Mathews and William Ellery Channing.]
June 22, 2007 at 10:57 am
select * from Table
where customerID = ISNULL(@customerID, customerID)
if the customerID is not NULLable field.
---------------------------------------------
[font="Verdana"]Nothing is impossible.
It is just a matter of time and money.[/font]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply