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 2000 Forums
 SQL Server Development (2000)
 Dynamic WHERE clauses

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-05 : 15:12:03
Bill writes "The stored proceedure I am working on below requires dynamic building of the where clause based on the values passed within the parameters supplied to the procedure.

If the parameter passed to @c_id is not null then include the following in the where clause: " and c.c_id = @c.c_id ". Else do not include anything else within the clause.

How can I create this flexability in my select statements?

CREATE PROCEDURE spGet_Registrant
@c_id int,
@c_user nvarchar(20),
@c_password nvarchar(20),
@myPLID int
AS
SELECT *
FROM tbl_comp c
WHERE c.c_user = @c_user
AND c.c_password = @c_password
AND c.pl_id = @myPLID"
   

- Advertisement -