Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Apr 16, 2012 07:50 AM|LINK
Do you mean writing the query out multiple times? So for each condition (optional parameter) I would have the whole query again but with the inclusion of the optional parameter? This is what I'm trying to avoid really. If I have 20 parameters and then want
to change part of the query itself it becomes time consuming. Certainly a step back from what is available in SQL. This is what I would do in SQL -
create proc sp_example
declare @sql varchar(500)
set @sql = '
Username = ' + @strUsername
if @intFacility <> '-1'
set @sql = @sql + ' and Facility = ' + @intFacility
if @param3 <> ''
set @sql = @sql + ' and field3 = ' + @param3
if @param4 <> ''
set @sql = @sql + ' and field4 = ' + @param4
Sorry if I've misunderstood what you mean?