Tim -

Whenever I try this, it fails testing when the @FirstName is ''. My SQL 
Server 2000 will not allow that value. My next choice is making the 
@FirstName optional. It appears that is possible, but (again) it does not 
work on my SQL Server 2000.

-brian

> You want something like this (not checked, so syntax may be off a
> little):
> 
> <cfset Variables.FirstName = "">
> <cfif IsDefined("Form.FirstName")>
>       <cfset Variables.FirstName = Form.FirstName>
> </cfif>
> 
> <cfset Variables.ZipsReturned = "">
> <cfif IsDefined("Form.ZipsReturned ")>
>       <cfset Variables.ZipsReturned = Form.ZipsReturned >
> </cfif>
> 
> <cfquery datasource="blah" name="blahquery">
>       FindProfiles '#Variables.FirstName#', '#Variables.ZipsReturned#'
> </cfquery>
> 
> Then, in your database, create this stored procedure by copy/pasting the
> following into a Query Analyzer or other such window:
> 
> create procedure FindProfiles
>       @FirstName varchar(255),
>       @ZipsReturned varchar(8000)
> 
> as
> 
> set nocount on
> 
> declare @SQL varchar(8000), @WhereClause varchar(8000)
> 
> set @SQL = 'select * from Profiles
> set @WhereClause = ''
> 
> if @FirstName > ''
>       begin
>               if @WhereClause > '' set @WhereClause = @WhereClause 
= '
> and '
>               set @WhereClause = @WhereClause + 'FirstName = ''' +
> @FirstName + ''''
>       end
> 
> if @ZipsReturned > ''
>       begin
>               if @WhereClause > '' set @WhereClause = @WhereClause 
= '
> and '
>               set @WhereClause = @WhereClause + 'Zipcode in (' +
> @ZipsReturned + ')'
>       end
> 
> if @WhereClause > '' set @SQL = @SQL + ' where ' + @WhereClause
> 
> execute (@SQL)
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2133
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/6
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:6
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to