SteveInBeloit
3/15/2007 4:33:00 PM
Sorry for the incompleteness, I am always leary of getting too long of a post.
The whole where claus is:
WHERE odRcvdDt >= @FromDate AND odRcvdDt <= @ToDate AND odShipCmplt = 1
AND cmCustName LIKE COALESCE (NULLIF (@Company + '%', ''), cmCustName)
AND ohPO LIKE COALESCE (NULLIF (@PO + '%', ''), ohPO)
AND odShopTktDieNo LIKE COALESCE (NULLIF(@Die + '%', ''), odShopTktDieNo)
AND odColor LIKE COALESCE (NULLIF('%' + @Color + '%', ''), odColor)
AND cpCustomerItem LIKE COALESCE (NULLIF(@PartNo, '')+'%', cpCustomerItem)
I pass in any combinations of these parameters, or null for the ones I do
not want to filter on.
For Color for example, if the color is spaces in the table, I get it back,
if it is NULL in the table, I get nothing. Maybe I am getting nothing when
other fields are NULL also and I just don't know it?
Thanks
"Tom Cooper" wrote:
> First, since odColor contains NULL,
>
> Where odColor LIKE ...
>
> will never return true no matter what is on the right side of the LIKE
> clause.
>
> Second, I don't understand why you wrote the right side of your expression
> the way you did. Since '%' + @Color + '%' cannot possibly be the empty
> string '', NULLIF('%' + @Color + '%', '') will always give you the value of
> '%' + @Color + '%', so the NULLIF function is not needed.
>
> Please explain what you are trying to do and we can probably help you
> rewrite this.
>
> Tom
>
> "SteveInBeloit" <SteveInBeloit@discussions.microsoft.com> wrote in message
> news:937B6857-AA3E-454A-82C9-35E4EE487425@microsoft.com...
> > Hi,
> > I have a Select statement that uses Coalesce with Nullif in the Where
> > clause. I thought all has been working good. I found a row that it is
> > not
> > returning and have it narrowed down to this line in the Where:
> >
> > AND odColor LIKE COALESCE (NULLIF('%' + @Color + '%', ''), odColor)
> >
> > I pass @Color in as NULL. odColor contains NULL in the table. If I
> > comment
> > this line out, I get the row, if I uncomment it, I do not get it.
> >
> > What am I not seeing?
> > Thanks,
> > Steve
>
>
>