Re: Conditional SQL

2007-06-14 Thread Jochem van Dieten
James Smith wrote: >> I don't think that is a very good solution. Not only can this not use >> any indexes, it will also not match "Friends Season 7 - Complete Series" >> because the order of the words doesn't match. > > I was originally breaking the string and doing several 'and's. I do need to

RE: Conditional SQL

2007-06-14 Thread James Smith
> I don't think that is a very good solution. Not only can this not use > any indexes, it will also not match "Friends Season 7 - Complete Series" > because the order of the words doesn't match. I was originally breaking the string and doing several 'and's. I do need to look into "Full Text Inde

Re: Conditional SQL

2007-06-13 Thread Jochem van Dieten
James Smith wrote: > As a last resort this procedure does the following... > > SET @searchTerm = '%' + REPLACE(@searchTerm,' ','%') + '%'; > .. > .. > .. > AND (Title LIKE @searchTerm OR ArtistName LIKE @searchTerm) > > So that is someone searches for 'friends series 7' it is first turned into

Re: Conditional SQL

2007-06-13 Thread Robertson-Ravo, Neil (RX)
3 17:32:04 2007 Subject: Re: Conditional SQL On 6/13/07, James Smith <[EMAIL PROTECTED]> wrote: > As a last resort this procedure does the following... > > SET @searchTerm = '%' + REPLACE(@searchTerm,' ','%') + '%'; > .. > .. > .. >

Re: Conditional SQL

2007-06-13 Thread Dean Lawrence
On 6/13/07, James Smith <[EMAIL PROTECTED]> wrote: > As a last resort this procedure does the following... > > SET @searchTerm = '%' + REPLACE(@searchTerm,' ','%') + '%'; > .. > .. > .. > AND (Title LIKE @searchTerm OR ArtistName LIKE @searchTerm) > > So that is someone searches for 'friends se

RE: Conditional SQL

2007-06-13 Thread Gaulin, Mark
to use a "full text" searching query ("CONTAINS") and not LIKE. Mark -Original Message- From: James Smith [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 13, 2007 11:56 AM To: CF-Talk Subject: RE: Conditional SQL As a last resort this procedure does the follo

RE: Conditional SQL

2007-06-13 Thread James Smith
As a last resort this procedure does the following... SET @searchTerm = '%' + REPLACE(@searchTerm,' ','%') + '%'; .. .. .. AND (Title LIKE @searchTerm OR ArtistName LIKE @searchTerm) So that is someone searches for 'friends series 7' it is first turned into '%friends%series%7%' which will mat

RE: Conditional SQL

2007-06-13 Thread James Smith
> This seems like a really complicated way of saying "AND ((ProductGroupID > = @productgroupid) OR (@productgroupid = 0))". Am I missing something? Works perfectly... Simplest solutions are always the best, cheers. -- Jay ~|

Re: Conditional SQL

2007-06-13 Thread Jim Wright
On 6/13/07, Gaulin, Mark <[EMAIL PROTECTED]> wrote: > This seems like a really complicated way of saying "AND ((ProductGroupID > = @productgroupid) OR (@productgroupid = 0))". Am I missing something? > I think "really" complicated is a bit harsh...perhaps "more" complicated...and the previous ver

RE: Conditional SQL

2007-06-13 Thread Gaulin, Mark
This seems like a really complicated way of saying "AND ((ProductGroupID = @productgroupid) OR (@productgroupid = 0))". Am I missing something? -Original Message- From: Jim Wright [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 13, 2007 7:31 AM To: CF-Talk Subject: Re: Condi

Re: Conditional SQL

2007-06-13 Thread Jim Wright
On 6/13/07, James Smith <[EMAIL PROTECTED]> wrote: > > AND ProductGroupID = CASE WHEN @productgroupid > 0 THEN > > @productgroupid ELSE ProductGroupID END > > This is the simplest to read but has a drawback, it the stored > ProductGroupID is null then the statement becomes AND ProductGroupID = > Pr

RE: Conditional SQL

2007-06-13 Thread James Smith
> AND ProductGroupID = CASE WHEN @productgroupid > 0 THEN > @productgroupid ELSE ProductGroupID END This is the simplest to read but has a drawback, it the stored ProductGroupID is null then the statement becomes AND ProductGroupID = ProductGroupID and for some reason NULL does not equal NULL so t

Re: Conditional SQL

2007-06-12 Thread Jochem van Dieten
James Smith wrote: > the query is actually very complex involving several loops and a few > conditional clauses Your query has several loops? You mean you actually use the new hierargical query features of MS SQL 2005? Or does the CF code that generates the query involve several loops and condit

Re: Conditional SQL

2007-06-12 Thread James Smith
the query is actually very complex involving several loops and a few conditional clauses and I am hoping that by sticking it all into a stored procedure it will be precompiled by MSSQL and therefore more efficient. On 12/06/07, Jochem van Dieten <[EMAIL PROTECTED]> wrote: > James Smith wrote: > >

Re: Conditional SQL

2007-06-12 Thread Jochem van Dieten
James Smith wrote: > > SELECT Title, ProductID > FROM aTable > WHERE Stock > 0 > > AND ProductGroupID = #val(productgroupid)# > > > I wish to move this query into MSSQL server for performance reasons Which performance reasons? Why do you expect an improvement of the performance from moving

Re: Conditional SQL

2007-06-12 Thread Jim Wright
> > I wish to move this query into MSSQL server for performance reasons, how do > I go about running the conditional code? I have tried... > I'm not sure you are going to get the performance benefit you are looking for. Doing the conditional processing in SQL isn't necessarily going to be faster

Re: Conditional SQL

2007-06-12 Thread Gert Franz
You could use the CASE statement instead. Or you could write a stored procedure which does exactly the thing you want. DECLARE @productgroupid bigint; SET @productgroupid = 5; IF @productgroupid > 0 BEGIN SELECT Title, ProductID FROM aTable WHERE Stock > 0 AND

Re: Conditional SQL

2007-06-12 Thread James Wolfe
You can do the following and then run the query as DECLARE @productgroupid int; SET @productgroupid = #queryParams.productgroupid#; SELECT Title, ProductID FROM aTable WHERE Stock > 0 AND m.ProductGroupID = coalesce(nullIf(@productgroupid,-10001),m.ProductGroupID) W

Re: Conditional SQL

2007-06-12 Thread koen darling
Try this: DECLARE @productgroupid bigint; SET @productgroupid = 5; SELECT Title, ProductID FROM aTable WHERE Stock > 0 AND (m.ProductGroupID = @productgroupid AND @productgroupid > 0) Koen ~| ColdFusion MX7 and Flex 2 Bu

Conditional SQL

2007-06-12 Thread James Smith
I currently have a (very complex) query in the format... SELECT Title, ProductID FROM aTable WHERE Stock > 0 AND ProductGroupID = #val(productgroupid)# I wish to move this query into MSSQL server for performance reasons, how do I go about running the conditional code? I have tried... DE

RE: Conditional SQL Query Not Working

2003-07-03 Thread Costas Piliotis
Sent: Thursday, July 03, 2003 6:17 AM To: CF-Talk Subject: Conditional SQL Query Not Working I have a form, that asks for a number of 'conditions' in order to find an attendee for a course. The problem is, I've put together a query that returns too many results / not the correct

Re: Conditional SQL Query Not Working

2003-07-03 Thread Jochem van Dieten
Jillian Carroll wrote: > I have a form, that asks for a number of 'conditions' in order to find an > attendee for a course. The problem is, I've put together a query that > returns too many results / not the correct results. Every row returned is > returned multiple times. I'm wondering if I'm

Conditional SQL Query Not Working

2003-07-03 Thread Jillian Carroll
I have a form, that asks for a number of 'conditions' in order to find an attendee for a course. The problem is, I've put together a query that returns too many results / not the correct results. Every row returned is returned multiple times. I'm wondering if I'm needing a join somewhere... or i