SQL: Return “true” if list of records exists?

后端 未结 14 869
情深已故
情深已故 2020-12-28 12:49

An alternative title might be: Check for existence of multiple rows?

Using a combination of SQL and C# I want a method to return true if all products in a list exist

14条回答
  •  青春惊慌失措
    2020-12-28 13:31

    I know this is old but I think this will help anyone else who comes looking...

    SELECT CAST(COUNT(ProductID) AS bit) AS [EXISTS] FROM Products WHERE(ProductID = @ProductID)
    

    This will ALWAYS return TRUE if exists and FALSE if it doesn't (as opposed to no row).

提交回复
热议问题