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)
 Building a Select Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-26 : 09:16:21
TDawg writes "I would like to build a select query dynamically in a stored proc. We I try this it doesn't work. Is there anyway to do this with stored procedure.

Ex.
Select * FROM tblUsers
WHERE
If Len(FName) > 0 Then
Firstname = FName AND
End if

If Len(Lname) > 0 Then
Lastname = Lname
End If

I would like to do this in a stored proc, but I am having a lot of problems. Any ideas?"

andre
Constraint Violating Yak Guru

259 Posts

Posted - 2002-02-26 : 09:33:01
You could do this without dynamic SQL:


Select * FROM tblUsers WHERE FirstName=IsNull(@FName,Firstname) AND
Lastname=IsNull(@Lname,Lastname)


Go to Top of Page
   

- Advertisement -