我尝试四处寻找,但找不到任何可以帮助我的东西。
我正在尝试在 SQL 中执行此操作:
declare @locationType varchar(50); declare @locationID int; SELECT column1, column2 FROM viewWhatever WHERE CASE @locationType WHEN 'location' THEN account_location = @locationID WHEN 'area' THEN xxx_location_area = @locationID WHEN 'division' THEN xxx_location_division = @locationID
我知道我不应该把’= @locationID’放在每一个的末尾,但我无法得到接近正确的语法。SQL 在第一行 WHEN 上一直抱怨我的“=”…
我怎样才能做到这一点?
declare @locationType varchar(50); declare @locationID int; SELECT column1, column2 FROM viewWhatever WHERE @locationID = CASE @locationType WHEN 'location' THEN account_location WHEN 'area' THEN xxx_location_area WHEN 'division' THEN xxx_location_division END