s

mssql how to use exists in select list edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 18 October 2020 | 1989

How to use EXISTS in a select statement where you want to return a boolean column

Solution

select  Item.Id as ItemId, Item.Name, SKU, Item.Name as ImageUrl, 
CAST(CASE WHEN EXISTS(select * from ItemSimilarMapping where ItemId=@ItemId and ItemSimilarMapping.SimilarItemId = Item.Id) THEN 1 ELSE 0 end as bit) As IsSimilar
from Item