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 2000 Forums
 SQL Server Development (2000)
 Determining Which Combination of Values Exist

Author  Topic 

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2001-04-11 : 13:23:26
Is there an easier, shorter way to do this

DECLARE @x int
select @X = COUNT(DISTINCT Corrosive) from MyTable where UOM = 'en' AND Corrosive = 'Corrosive'
DECLARE @y int
select @y = COUNT(DISTINCT Corrosive) from MyTable where UOM = 'en' AND Corrosive = 'Non-Corrosive'

DECLARE @z int
SELECT @z = CASE
WHEN @x = 0 AND @y = 0 THEN 0 /*When None exist*/
WHEN @x = 1 AND @y = 0 THEN 1 /*When Corrosive Exists*/
WHEN @x = 0 AND @y = 1 THEN 2 /*When Non-Corrosive Exists*/
WHEN @x = 1 AND @y = 1 THEN 3 /*When Both Exist*/
END

PRINT @z



   

- Advertisement -