dbTalk Databases Forums  

help with parameter in WHERE

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss help with parameter in WHERE in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
knowzero
 
Posts: n/a

Default help with parameter in WHERE - 03-21-2007 , 02:22 PM






my query:
select Product_List.*, Product_Sales.*
from Product_List
left outer join Product_Sales on Product_List.ID = Product_Sales.ID

this works fine. its simple. I have this in a report and I would like
to add a parameter @p1 to add to the query

where Product_Sales.Order_Amount >= @p1

my problem is that if @p1 is null I want to retrieve all recorders in
Product_List. any ideas.

Do you need more clarification.


Reply With Quote
  #2  
Old   
Jack Vamvas
 
Posts: n/a

Default Re: help with parameter in WHERE - 03-21-2007 , 02:44 PM






Try:

where Product_Sales.Order_Amount =
CASE
when @p1 is null then Product_Sales.Order_Amount
else @p
END


--

Jack Vamvas
___________________________________
Advertise your IT vacancies for free at - http://www.ITjobfeed.com



"knowzero" <isacp (AT) bhphoto (DOT) com> wrote

Quote:
my query:
select Product_List.*, Product_Sales.*
from Product_List
left outer join Product_Sales on Product_List.ID = Product_Sales.ID

this works fine. its simple. I have this in a report and I would like
to add a parameter @p1 to add to the query

where Product_Sales.Order_Amount >= @p1

my problem is that if @p1 is null I want to retrieve all recorders in
Product_List. any ideas.

Do you need more clarification.




Reply With Quote
  #3  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: help with parameter in WHERE - 03-21-2007 , 03:03 PM



On 21 Mar 2007 12:22:38 -0700, knowzero wrote:

Quote:
my query:
select Product_List.*, Product_Sales.*
from Product_List
left outer join Product_Sales on Product_List.ID = Product_Sales.ID

this works fine. its simple. I have this in a report and I would like
to add a parameter @p1 to add to the query

where Product_Sales.Order_Amount >= @p1

my problem is that if @p1 is null I want to retrieve all recorders in
Product_List. any ideas.
Hi knowzero,

WHERE Product_Sales.Order_Amount >= COALESCE(@p1,
Product_Sales.Order_Amount)

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis


Reply With Quote
  #4  
Old   
Ed Murphy
 
Posts: n/a

Default Re: help with parameter in WHERE - 03-21-2007 , 05:56 PM



knowzero wrote:

Quote:
my query:
select Product_List.*, Product_Sales.*
from Product_List
left outer join Product_Sales on Product_List.ID = Product_Sales.ID

this works fine. its simple. I have this in a report and I would like
to add a parameter @p1 to add to the query

where Product_Sales.Order_Amount >= @p1

my problem is that if @p1 is null I want to retrieve all recorders in
Product_List. any ideas.
where @p1 is null or Product_Sales.Order_Amount >= @p1


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.