Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help =(

Author  Topic 

Ravius
Starting Member

13 Posts

Posted - 2009-08-11 : 05:45:00
Hi guys, i am currently a student and i am new in this. Hope you guys can help me out. Thanks in advance (:

Currently, I got this select statement that takes in user input to do this query. How do i make it so that if user didn't input any of the parameter, it will select all from other parameter?

For example, if user input for all the other parameter EXCEPT for the @CID, the query will ignore @CID and search based on the other parameter.

====below are the initial query i am with====

SELECT ROW_NUMBER() OVER (ORDER BY Products.PID),
Products.PID, Pname, Price
FROM Products
WHERE Products.CID = @CID
and Products.CountryID = @CountryID
and Products.AreaID = @AreaID
and Products.CategoryID = @CatID
and Products.ProductCategoryID = @PCID

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-11 : 05:46:07
SELECT ROW_NUMBER() OVER (ORDER BY Products.PID),
Products.PID, Pname, Price
FROM Products
WHERE (@CID IS NULL OR Products.CID = @CID)
and Products.CountryID = @CountryID
and Products.AreaID = @AreaID
and Products.CategoryID = @CatID
and Products.ProductCategoryID = @PCID
Go to Top of Page

Ravius
Starting Member

13 Posts

Posted - 2009-08-11 : 05:50:18
ooh! bklr thanks!! (:
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-11 : 05:54:10
welcome
Go to Top of Page
   

- Advertisement -