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.
Author |
Topic |
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-08-08 : 13:12:53
|
hi there i need to do a select but i have 2 possible casesand i need your help pleasefirst casei have no problem with this casetable called "products"idproduct name1 aple2 cherry3 strawberrythis case is easy beacuase i do a select this way and i get all the itemsselect idproduct , namefrom productsand i get thisidproduct name1 aple2 cherry3 strawberrynow i show you the other case when in my table products where i dont have a record with idproduct=1table called "products"idproduct name2 cherry3 strawberryand i need to do a select that gives me this resultidproduct name1 strawberry2 cherryas you can see ( that i need its when the idproduct=1 doesnt exists the idproduct = 3 takes the idproduct=1)any ideas pleasemany thanks in advancedkind regards |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-08 : 13:49:07
|
[code]select idproduct,namefrom(select case when sum(case when idproduct=1 then 1 else 0 end) over () = 0 and idproduct=3 then 1 else idproduct end as idproduct,namefrom products)pwhere idproduct=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-08-08 : 18:31:59
|
thanks a lotgreat querythanks for always helping people |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-08 : 18:56:59
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|