I want to return an extra computed column as bit开发者_如何学Go for each rowID that exist as foreign ke in Joined table.for example: Select PId, PName from Part where PId in (Select distinct FkPid in joined Part
Result should be like Pid| PName|Bit|
Thanks
Select PId, PName, CAST(CASE WHEN B.fkPid IS NULL THEN 0 ELSE 1 END AS BIT) ExistsOtherTable
from Part A
LEFT JOIN (Select distinct FkPid FROM [joined Part]) B
ON A.PId = B.fkPid
Simply do a left join!!!!
Select PId, PName, cast (isnull(OtherTable.FkPid,0) as bit) as [Bit] from Part left join
OtherTable on Part.PId=OtherTable.FkPid
精彩评论