2016-05-04 50 views
0

我想從這個大小寫參數的巢中的2個值,所以我可以將它們插入結果表來檢查匹配,然後我更新#game表的結果。我已將更新作爲select語句的一部分。 我得到我怎樣才能得到嵌套的大小寫參數返回值

無效列錯誤

standard_matchesbonus_match。 然後我嘗試在case參數和相同的錯誤後獲取一個值。 這是大小寫參數代碼。

BEGIN -- 
    -- update #game set gwn = standard_matches ,gsn = bonus_match from 
-- where gameno = 1 
    -- from 
     SELECT 
      @Ball1 AS Ball1, 
      @Ball2 AS Ball2, 
      @Ball3 AS Ball3, 
      @Ball4 AS Ball4, 
      @Ball5 AS Ball5, 
      @Ball6 AS Ball6, 
      standard_matches 
      bonus_match 
     from #draws 
    CROSS APPLY 
     (SELECT 
      CASE WHEN Winningball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 end + 
      CASE WHEN Winningball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 ENd + 
      CASE WHEN Winningball3 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball4 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball5 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball6 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as standard_matches, 
      CASE WHEN Bonusball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Bonusball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as bonus_match 
     ) AS ca1 
     set @sm = standard_matches 
     set @bm = bonus_match 
     update #game set gwn = @sm ,gsn = @bm where gno = 1 
end 

回答

0

我想這就是你想要的?

; WITH ca1 AS 
(
    SELECT 
      standard_matches, -- missing comma 
      bonus_match 
     from #draws 
    CROSS APPLY 
     ( 
     SELECT 
      CASE WHEN Winningball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 end + 
      CASE WHEN Winningball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 ENd + 
      CASE WHEN Winningball3 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball4 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball5 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Winningball6 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as standard_matches, 
      CASE WHEN Bonusball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + 
      CASE WHEN Bonusball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as bonus_match 
     ) a 
) 
UPDATE g 
SET gwn = ca1.standard_matches, 
    gsn = ca1.bonus_match 
FROM #game g 
CROSS JOIN ca1 
WHERE g.gno = 1 
+0

感謝您的回答,我仍然在select和update語句中獲得了standard_matches和bonus_match的錯誤無效列名稱。案例參數可以看到列爲int – Gary

+0

你可以發佈你的最新查詢嗎? – Squirrel

+0

嗨松鼠列名不一樣這是代碼 – Gary

相關問題