我有一定的困難,在嘗試比較了一定的成效,基本的SQL Server +對輸出進行比較的結果
(選擇[DishId] FROM [Package_Set_Dish],其中[Package_Set_Id] = COALESCE((SELECT [SETID ] FROM [Package_Schedule_Set_Daily] WHERE [自動識別] = @PkSchSetId),(SELECT [SETID] FROM [Package_Schedule_Set_Weekly] WHERE [自動識別] = @PkSchSetId)
將返回3條記錄(不按順序):
1
2
10
或
1
10
2
基本上,如果傳入SPROC變量@ 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)