Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-11-20 : 03:42:45
my current query is

select p.productid,p.productname,p.manufacturerid,p.manufacturersku,p.description,p.shortdescription,p.keywords,p.weight,p.weightunit,p.productlength,p.productwidth,p.productheight,p.dimensionunits,o.cost,o.price as unitprice,o.listprice as listprice,p.quantityinstock,p.stockdisplay,o.shippingprice,p.taxable,p.productlink,p.callforprice,p.callforpricemessage,p.active,p.deleted,p.dateadded,p.datedeleted,p.minimumstocklevel,p.featuredincategories,p.handlingfeeid,p.specs,p.itemincludes,p.surcharge,p.freeshipping,p.availability,p.metakeywords,p.metadescription,p.nohtmldesc,o.optionname,o.variantsku as merchantsku,o.optionid,o.image from products p left join productstooptiongroups ptg on p.productid=ptg.productid
left join options o on o.optiongroupid=ptg.optiongroupid




problem is there are some products that don't have any record in the productstoptionsgroups (no options)
for these products i need to take the listprice and unitprice from products and not options -- how can i do this? like if the options exist the listprice is the price field from options and if not then it's the listprice field from products?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-20 : 03:47:15
Use a case statement on listprice and price:


case when o.listprice is null then p.unitprice else o.listprice end as price

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-11-20 : 04:10:09
also you can do in this way:-
ISNULL(o.listprice,p.listprice) AS 'Price'
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-11-20 : 04:22:10
thanks :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-20 : 05:39:03
quote:
Originally posted by visakh16

also you can do in this way:-
ISNULL(o.listprice,p.listprice) AS 'Price'


Or COALESCE in place of ISNULL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -