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
 Transact-SQL (2000)
 dynamic query using if and else

Author  Topic 

supergirl_gem
Starting Member

4 Posts

Posted - 2006-03-09 : 08:29:45
Hi,

I'm fairly new to Transact SQL and stored procedures, so i'm really struggling to find the solution to my problem.

I have a web page with a search facility with three options
2 drop down menus and a text field. The user doesn't have to select all options to continue, the two drop down menus have an all option.

If the user selects all then i just want to do a select * from my database, otherwise i want to do a select * from MyDatabase where fieldName = parameter also if the other fields are selected i will need an and to so i need to check if the sql string has something in it then add and fieldType2 = parameter 2 on the end if it does have something in it otherwise where fieldName2 = parameter2

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2006-03-09 : 09:22:52
Create a stored procedure that uses dynamic SQL.

http://www.sqlteam.com/item.asp?ItemID=233
Go to Top of Page
   

- Advertisement -