SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 using case in join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

svibuk
Yak Posting Veteran

62 Posts

Posted - 08/14/2013 :  01:46:36  Show Profile  Reply with Quote
i have a subquery in which i need to use case statement for using join


have the following

MID IN (SELECT HId
FROM TBLDETAILS D
INNER JOIN TBLMAS M on
M.ID= D.DID
WHERE M.MID<>0 )

need to add a case statement as below
but it gives error
MID IN (SELECT HId
FROM TBLDETAILS D
INNER JOIN TBLMAS M on
case when type='M' THEN
M.ID= D.DID
ELSE
M.MID=D.MID
END
WHERE M.MID<>0)

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 08/14/2013 :  03:01:39  Show Profile  Reply with Quote
try this...
MID IN (SELECT HId FROM TBLDETAILS D 
		INNER JOIN TBLMAS M on
		(M.ID = case when type='M' THEN D.DID END)
		OR (M.MID = CASE WHEN type !='M' THEN D.MID END)
		WHERE M.MID<>0)


--
Chandu
Go to Top of Page

svibuk
Yak Posting Veteran

62 Posts

Posted - 08/14/2013 :  03:31:31  Show Profile  Reply with Quote
Thanks very much
solved my issue
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 08/14/2013 :  03:45:31  Show Profile  Reply with Quote
quote:
Originally posted by svibuk

Thanks very much
solved my issue


welcome

--
Chandu
Go to Top of Page

ShivaKrishna
Starting Member

India
20 Posts

Posted - 08/28/2013 :  07:41:24  Show Profile  Reply with Quote
MID IN (SELECT HId
FROM TBLDETAILS D
INNER JOIN TBLMAS M on
( type='M' and M.ID= D.DID)
INNER JOIN TBLMAS M2 on
M2.MID=D.MID
WHERE M.MID<>0 AND M2.MID<>0 )
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000