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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-18 : 08:33:01
|
| Sharon writes "I am new to SQL and I am trying to filter information for a products web page I am building. Here is the SQL statement I have at the moment which is totally wrong...SELECT Prod_ID, Prod_Name, Prod_Price, Prod_ImageFROM Product_ItemWHERE Prod_Price = 'SmallPrice'IF 'SmallPrice' IS NOT NULLTHEN 'SmallPrice'ELSE 'MediumPrice' IS NOT NULLTHEN 'MediumPrice' END IFORDER BY Prod_Name ASCI am trying to show all products on the page with the product name, price and image. However, I want to filter the price information because each product has several different prices depending on it's size. The way I want to filter it is by displaying the small price,(next to the word from:), and if the product doesn't come in small, then I want to display the medium price. Does this make sense? I hope so...Can someone help me out. I'm sure this is simple for someone on the SQL team! :)Thank you!Sincerely,Sharon" |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-11-18 : 08:52:42
|
| In this case you might use the COALESCE functionSELECT COALESCE(SmallPrice,MediumPrice) AS Prod_Price FROM Product_ItemThis will take the first NON NULL value of SmallPrice,MediumPrice.For conditional programming in SQL Server you can use the CASE statement:CASE WHEN <condition1> THEN <dothis> WHEN <condition2> THEN <dothat> ELSE <dozip> ENDrockmoose |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-11-18 : 09:29:05
|
quote: Simple SQL help for a newbie... very newbie
I read your blog Jeff, very nice.I would call that stuff, advanced ?rockmoose |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-11-18 : 11:10:10
|
| i guess it depends on your background; if you are good with logic and boolean expressions and programming in general, but new at SQL, it should be helpful; if you are new to computers/programming in general and especially logic, then it may be too complicated.but the overall logical concept of:IF A THEN B (or "A -> B" or "A implies B")being equivalent to (Not A) or Bis a very handy thing to know !- Jeff |
 |
|
|
|
|
|
|
|