well the way the procedure works, is it only adds the column to the where clause, if it's NOT set to the default, or if it's NOT null. see belowSET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOALTER PROCEDURE search_orders_1 @lowage int = null, @highage int = null, @highwealth int = null, @lowwealth int = null, @highpurprice int = null, @lowpurprice int = null, @lowmtgamt int = null, @highmtgamt int = null, @lowincome char(3) = null, @highincome char(3) = null, @marriedstat char(3) = null, @lowyearbuild char(4) = null, @highyearbuild char(4) = null, @mtgpresstat char(3) = null, @lenderpresstat char(3) = null, @ratets char(3) = null, @loants char(10) = null, @childstat char(3) = null, @homeownerstat char(10) = null, @lowpurdate char(8) = null, @highpurdate char(8) = null, @addresstype char(3) = null, @SPSir char(3) = null, @debttype char(3) = null, @dwelltype char(3) = null, @zipselect nvarchar(4000) = null, @acselect nvarchar(4000) = null, @stselect nvarchar(4000) = null, @cityselect nvarchar(4000) = null, @counselect nvarchar(4000) = null,-- as @debug bit = 0 AS DECLARE @sql nvarchar(4000), @paramlist nvarchar(4000) if @spsir='1' select @sql = @sql+ 'SELECT o.state_abbrv, count(o.state_abbrv) as kount FROM dbo.mortgage o left join dbo.Spanish on o.per1_lname = spanish.lname'if @spsir='2' select @sql = @sql+ 'SELECT distinct o.state_abbrv, count(o.state_abbrv) as kount FROM dbo.mortgage o inner join dbo.Spanish on o.per1_lname = spanish.lname'if @spsir='ALL' or @spsir is null SELECT @sql = 'SELECT o.state_abbrv, count(o.state_abbrv) as kount FROM dbo.mortgage o'select @sql=@sql+' WHERE 1 = 1'if @spsir='2' select @sql = @sql+ ' and spanish.lname is null' IF @lowage<>0 and @lowage is not null SELECT @sql = @sql + ' AND o.per1_age >= @xlowage' IF @highage<>0 and @highage IS NOT null SELECT @sql = @sql + ' AND o.per1_age <= @xhighage' IF @lowincome<>'DF' and @lowincome IS NOT NULL SELECT @sql = @sql + ' AND o.est_inc >= @xlowincome' IF @highincome<>'DF' and @highincome IS NOT NULL SELECT @sql = @sql + ' AND o.est_inc <= @xhighincome' IF @highwealth<>0 and @highwealth IS NOT NULL SELECT @sql = @sql + ' AND o.wealth_rating <= @xhighwealth' IF @lowwealth<>0 and @lowwealth IS NOT NULL SELECT @sql = @sql + ' AND o.wealth_rating >= @xlowwealth' IF @highpurprice<>0 and @highpurprice IS NOT NULL SELECT @sql = @sql + ' AND o.hm_purprice <= @xhighpurprice' IF @lowpurprice<>0 and @lowpurprice IS NOT NULL SELECT @sql = @sql + ' AND o.hm_purprice >= @xlowpurprice' IF @lowyearbuild<>'DF' and @lowyearbuild IS NOT NULL SELECT @sql = @sql + ' AND o.hm_year_build >= @xlowyearbuild' IF @highyearbuild<>'DF' and @highyearbuild IS NOT NULL SELECT @sql = @sql + ' AND o.hm_year_build <= @xhighyearbuild' IF @lowmtgamt<>0 and @lowmtgamt IS NOT NULL SELECT @sql = @sql + ' AND o.oo_mtg_amnt >= @xlowmtgamt'IF @highmtgamt<>0 and @highmtgamt IS NOT NULL SELECT @sql = @sql + ' AND o.oo_mtg_amnt <= @xhighmtgamt' IF @lowpurdate<>'DF' and @lowpurdate IS NOT NULL SELECT @sql = @sql + ' AND o.hm_purdate >= @xlowpurdate' IF @highpurdate<>'DF' and @highpurdate IS NOT NULL SELECT @sql = @sql + ' AND o.hm_purdate <= @xhighpurdate' IF @marriedstat in ('M','S') SELECT @sql = @sql + ' AND o.per1_ms = @xmarriedstat' IF @ratets in ('V','F') SELECT @sql = @sql + ' AND o.oo_mtg_rate_t = @xratets' IF @homeownerstat in ('H','R') SELECT @sql = @sql + ' AND o.homeowner = @xhomeownerstat'IF @childstat in ('Y','N') SELECT @sql = @sql + ' AND o.child_pres = @xchildstat' IF @lenderpresstat ='Y' SELECT @sql = @sql + ' AND o.oo_mtg_lender_name<>+ '' ''' IF @lenderpresstat ='N' SELECT @sql = @sql + ' AND o.oo_mtg_lender_name=+ '' ''' IF @mtgpresstat='Y' SELECT @sql = @sql + ' AND o.oo_mtg_amnt>0'IF @mtgpresstat='N' SELECT @sql = @sql + ' AND o.oo_mtg_amnt=0'IF @loants<>'DF' and @loants IS NOT NULL SELECT @sql = @sql + ' and o.oo_mtg_loan_t in ( ''' + REPLACE( @loants, N',', N''',''' ) + N''' )'if @dwelltype='1' SELECT @sql = @sql + ' and o.addr_unit_desnum='' '''if @dwelltype='2' SELECT @sql = @sql + ' and o.addr_unit_desnum<>'' '''if @DebtType='1' select @sql = @sql + ' and o.pres_cc=''y'''if @DebtType='2' select @sql = @sql + ' and o.pres_perm_cc=''y'''if @addresstype='3' select @sql = @sql + ' and o.address1<>'' '''if @acselect <> 'DF' or @stselect <> 'DF' or @cityselect <> 'DF' or @counselect <> 'DF' or @zipselect <> 'DF' SELECT @sql = @sql + ' and (1=2'IF @acselect<>'DF' and @acselect IS NOT NULL SELECT @sql = @sql + ' OR o.areacode in ( ''' + REPLACE( @acselect, N',', N''',''' ) + N''' )' IF @stselect<>'DF' and @stselect IS NOT NULL SELECT @sql = @sql + ' OR o.state_abbrv in ( ''' + REPLACE( @stselect, N',', N''',''' ) + N''' )' IF @cityselect<>'DF' and @cityselect IS NOT NULL SELECT @sql = @sql + ' OR o.citystate in ( ''' + REPLACE( @cityselect, N',', N''',''' ) + N''' )' IF @counselect<>'DF' and @counselect IS NOT NULL SELECT @sql = @sql + ' OR o.countystate in ( ''' + REPLACE( @counselect, N',', N''',''' ) + N''' )'IF @zipselect<>'DF' and @zipselect IS NOT NULL SELECT @sql = @sql + ' OR o.zip in ( ''' + REPLACE( @zipselect, N',', N''',''' ) + N''' )'if @acselect <> 'DF' or @stselect <> 'DF' or @cityselect <> 'DF' or @counselect <> 'DF' or @zipselect <> 'DF' SELECT @sql = @sql + ')'SELECT @sql = @sql + ' group by o.state_abbrv ORDER BY o.state_abbrv ' IF @debug = 1 PRINT @sql SELECT @paramlist = '@xlowage int , @xhighage int , @xlowincome nvarchar(4000) , @xhighincome nvarchar(4000) , @xmarriedstat nvarchar(4000) , @xhighwealth int , @xlowwealth int , @xhighpurprice int , @xlowpurprice int , @xlowyearbuild nvarchar(4000) , @xhighyearbuild nvarchar(4000) , @xlowmtgamt int , @xhighmtgamt int , @xmtgpresstat nvarchar(4000) , @xlenderpresstat nvarchar(4000) , @xratets nvarchar(4000) , @xloants nvarchar(4000) , @xchildstat nvarchar(4000) , @xhomeownerstat nvarchar(4000) , @xlowpurdate nvarchar(4000) , @xhighpurdate nvarchar(4000) , @xzipselect nvarchar(4000) , @xacselect nvarchar(4000) , @xstselect nvarchar(4000) , @xcityselect nvarchar(4000) , @xcounselect nvarchar(4000)' EXEC sp_executesql @sql, @paramlist, @lowage , @highage , @lowincome , @highincome , @marriedstat , @highwealth , @lowwealth , @highpurprice , @lowpurprice , @lowyearbuild , @highyearbuild , @lowmtgamt , @highmtgamt , @mtgpresstat , @lenderpresstat , @ratets , @loants , @childstat , @homeownerstat , @lowpurdate , @highpurdate , @zipselect , @acselect , @stselect , @cityselect , @counselectGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOI'm thinking about maybe changing it to have EVERYTHING accept a few of them just coded in. to the where with the MAX/MIN values as the default. then i'll only have to set up a few indexes if i'm right. also, is SQL Smart enough to look at a select and know that it's gunna result in EVERYTHING so it just skips it?