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 |
|
tech2
Yak Posting Veteran
51 Posts |
Posted - 2011-08-07 : 20:29:31
|
| Why is the sql statement below excluding 'ProductID's' 680, 706, 709, & 710? The only row that should be excluded is ID 535.USE AdventureWorksSELECT * FROM Production.ProductWHERE ReorderPoint <> 600 AND Size IS NULLProductID Name ProductNumber ReorderPoint Size533 Seat Tube ST-9828 375 NULL534 Top Tube TO-2301 375 NULL535 Tension Pulley TP-0923 600 NULL679 Rear Derailleur Cage RC-0291 375 NULL680 HL Road Frame - Black, 58 FR-R92B-58 375 58706 HL Road Frame - Red, 58 FR-R92R-58 375 58707 Sport-100 Helmet, Red HL-U509-R 3 NULL708 Sport-100 Helmet, Black HL-U509 3 NULL709 Mountain Bike Socks, M SO-B909-M 3 M710 Mountain Bike Socks, L SO-B909-L 3 L711 Sport-100 Helmet, Blue HL-U509-B 3 NULLThanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-07 : 20:40:08
|
Your queryUSE AdventureWorksSELECT * FROM Production.ProductWHERE ReorderPoint <> 600 AND Size IS NULL[code]The Data[code]ProductID Name ProductNumber ReorderPoint Size533 Seat Tube ST-9828 375 NULL534 Top Tube TO-2301 375 NULL535 Tension Pulley TP-0923 600 NULL679 Rear Derailleur Cage RC-0291 375 NULL680 HL Road Frame - Black, 58 FR-R92B-58 375 58706 HL Road Frame - Red, 58 FR-R92R-58 375 58707 Sport-100 Helmet, Red HL-U509-R 3 NULL708 Sport-100 Helmet, Black HL-U509 3 NULL709 Mountain Bike Socks, M SO-B909-M 3 M710 Mountain Bike Socks, L SO-B909-L 3 L711 Sport-100 Helmet, Blue HL-U509-B 3 NULL The result should be those with BLUE AND green KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-08 : 04:58:58
|
| as you see the reason is because condition Size IS NULL does not hold good for 680, 706, 709, & 710 so they also get excluded------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tech2
Yak Posting Veteran
51 Posts |
Posted - 2011-08-08 : 10:17:07
|
quote: Originally posted by visakh16 as you see the reason is because condition Size IS NULL does not hold good for 680, 706, 709, & 710 so they also get excluded------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Thanks for replying visakh16 & khtan but I still don't have a statement that works. Do either of you have any ideas or suggestions. This should be a simple sql statement. The sql instruction is to exclude all rows that meet both conditions, which is ID 535. This is not happening. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-08 : 13:02:14
|
| [code]USE AdventureWorksSELECT * FROM Production.ProductWHERE NOT (ReorderPoint = 600 AND Size IS NULL)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|