Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
2242 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
2242 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  
 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.07 seconds. Powered By: Snitz Forums 2000