March 18, 2014 at 11:11 am
We want to not show line 1,3,5 for a specific order number #23565. We still want to see those order line numbers for all other sales orders.
This is the syntax we have:
select
soi.slord as ORDER_NO,
soi.slline as ORDER_LINE_NO
from
erp.svkincd
where
(slord <> 249486 and slline not in (1,3,5))
When we run it it does not show us any line 1,3,5 at all. Is there a way to get around that? Thank you in advance for any suggestions!
March 18, 2014 at 11:26 am
Someone will be along with a neater way to do this, but this would work
SELECT soi.slord as ORDER_NO,
soi.slline as ORDER_LINE_NO
FROM erp.svkincd
WHERE slord = '23565'
AND slline NOT IN (1,3,5)
UNION ALL
SELECT soi.slord as ORDER_NO,
soi.slline as ORDER_LINE_NO
FROM erp.svkincd
WHERE slord != '23565'
March 18, 2014 at 11:27 am
I added some sample data to test the solution, but you should provide it for us on future occasions to get faster and better help.
WITH svkincd (slord, slline) AS(
SELECT 249486, 1 UNION ALL
SELECT 249486, 2 UNION ALL
SELECT 249486, 3 UNION ALL
SELECT 249486, 4 UNION ALL
SELECT 249487, 1 UNION ALL
SELECT 249487, 2 UNION ALL
SELECT 249487, 3 UNION ALL
SELECT 249487, 4
)
SELECT *
FROM svkincd
WHERE NOT(slord = 249486 and slline in (1,3,5))
March 18, 2014 at 11:56 am
Thak you for the info!
March 18, 2014 at 3:52 pm
I think you were very close:
where
(slord <> 249486 or slline not in (1,3,5))
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
March 19, 2014 at 11:15 am
Try this.
select
soi.slord as ORDER_NO,
soi.slline as ORDER_LINE_NO
from
erp.svkincd
where
slord <> 23565
OR (slord = 23565
and slline not in (1,3,5))
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply