我在尝试比较一些结果时有点困难,基本上
(从 [Package_Set_Dish] 选择 [DishId] WHERE [Package_Set_Id] = COALESCE((从 [Package_Schedule_Set_Daily] 选择 [SetId] WHERE [AutoId] = @PkSchSetId),(从 [Package_Schedule_Set_Weekly] 选择 [SetId] WHERE [AutoId] = @PkSchSetId )
将返回 3 条记录(不按顺序):
1
2
10
或者
1
10
2
基本上,如果传入的存储过程变量@Dish_1、@Dish_2、@Dish_3 正好包含 1,2 和 10,我将返回 1(真)。如果它包含 1,2,2 或 1,10,10 它应该返回 0。
显然,下面的查询不会返回所需的结果。任何人都可以建议。谢谢。
SET @TempBit = (SELECT CASE WHEN
(@Dish_1 IN (SELECT [DishId] FROM [Package_Set_Dish] WHERE [Package_Set_Id]
= COALESCE((SELECT [SetId] FROM [Package_Schedule_Set_Daily]
WHERE [AutoId] = @PkSchSetId),
(SELECT [SetId] FROM [Package_Schedule_Set_Weekly] WHERE [AutoId] = @PkSchSetId)))
AND @Dish_2 IN (SELECT [DishId] FROM [Package_Set_Dish] WHERE [Package_Set_Id]
= COALESCE((SELECT [SetId] FROM [Package_Schedule_Set_Daily]
WHERE [AutoId] = @PkSchSetId)
, (SELECT [SetId] FROM [Package_Schedule_Set_Weekly] WHERE [AutoId] = @PkSchSetId)))
AND @Dish_3 IN (SELECT [DishId] FROM [Package_Set_Dish] WHERE [Package_Set_Id]
= COALESCE((SELECT [SetId] FROM [Package_Schedule_Set_Daily]
WHERE [AutoId] = @PkSchSetId)
, (SELECT [SetId] FROM [Package_Schedule_Set_Weekly] WHERE [AutoId] = @PkSchSetId)))
AND (SELECT [Date] FROM [Customer_Order_SwapSetDish]
WHERE [CustOrderId] = @CustOrderId) = @Date) THEN 1 ELSE 0 END AS BIT)