我正在处理以下简单查询。我想要内部小队和小组g表,但有条件(@ZeroOrOne参数将是0或1)
WHERE
CASE WHEN IsNumeric(@ZeroOrOne) = 0 THEN
s.TeamId=g.Team1Id --if @ZeroOrOne value is 0 then perform this statement
ELSE
s.TeamId=g.Team2Id --if @ZeroOrOne value is 1 then perform this statement
什么是正确的方法;我应该更改我的查询或逻辑吗?
答案 0 :(得分:1)
试试这个。
WHERE
s.TeamId = CASE WHEN IsNumeric(@ZeroOrOne) = 0 THEN g.Team1Id
ELSE g.Team2Id END
或者您也可以在ON子句中使用它
JOIN Table s
ON s.TeamId = CASE WHEN IsNumeric(@ZeroOrOne) = 0 THEN g.Team1Id
ELSE g.Team2Id END