If you are going down the dynamic SQL route you are better off keeping it in CF. Dynamic SQL is very inefficient and should be avoided wherever possible.
-----Original Message----- From: Raster, Tim [mailto:[EMAIL PROTECTED] Sent: 21 February 2005 22:03 To: SQL Subject: RE: How 2 convert cfquery to TSQL (MS SQL stored proc) 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) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Discover CFTicket - The leading ColdFusion Help Desk and Trouble Ticket application http://www.houseoffusion.com/banners/view.cfm?bannerid=48 Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2137 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=89.70.6 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
