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
 Transact-SQL (2000)
 Case statement in join with multiple values

Author  Topic 

jonesboy21
Starting Member

2 Posts

Posted - 2006-10-31 : 09:15:21
Any ideans on how or if I can actually use a case statment in this respect:

INNER JOIN dbo.ufnTopEmpIdentification(null,@EDICreateDate) ei on ei.personid = p.personid
AND ei.EmpCatId IN (CASE WHEN @PRCycleTypeCode IN ('NB','SB') THEN ('1') ELSE ('2,3') END )

Throws this error:
Syntax error converting the varchar value '2,3' to a column of data type int.


I did try using integers instead of characters, i.e.
(CASE WHEN @PRCycleTypeCode IN ('NB','SB') THEN (1) ELSE (2,3) END )

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-31 : 09:17:37
The ELSE part can only return 1 value.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-31 : 09:20:43
[code]INNER JOIN dbo.ufnTopEmpIdentification(null,@EDICreateDate) ei on ei.personid = p.personid
WHERE CASE
WHEN @PRCycleTypeCode IN ('NB','SB') AND ei.EmpCatId IN (1) THEN 1
WHEN @PRCycleTypeCode NOT IN ('NB','SB') AND ei.EmpCatId IN (2, 3) THEN 1
ELSE 0
END = 1[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-31 : 09:58:58
or use simple if else

IF @PRCycleTypeCode IN ('NB','SB')
SELECT.....
INNER JOIN dbo.ufnTopEmpIdentification(null,@EDICreateDate) ei on ei.personid = p.personid
AND ei.EmpCatId IN (1)
ELSE
SELECT.....
INNER JOIN dbo.ufnTopEmpIdentification(null,@EDICreateDate) ei on ei.personid = p.personid
AND ei.EmpCatId IN (2,3)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jonesboy21
Starting Member

2 Posts

Posted - 2006-10-31 : 13:36:56
Thank you Peso, your solution worked perfectly! I appreciate your help
Go to Top of Page
   

- Advertisement -