我创建了这个简化的 sql 查询。它需要一个只有 2 个字符的级别代码(“GR”、“PH”...等),我需要更改查询以允许在一个实例中返回多个项目。
这是代码
DECLARE @ALEVL_CODE varchar(5), @test varchar(100)
SET @ALEVL_CODE = 'GR'
SET @test = @ALEVL_CODE + ',' + 'PH'
-
select ALEVL_CODE from PMP_Admissions_Letter_Data AD
INNER JOIN PMP_LM_Review LMR
ON LMR.PMP_Letter_Data_ID = AD.PMP_Admissions_Letter_Data_ID
WHERE LMR.ToPrinter = 1 AND
LMR.Extracted = 0 AND
AD.ALEVL_CODE = @ALEVL_CODE
AND
AD.DSCN_MAX_CODE = 'PA'
我遇到的问题是AD.ALEVL_CODE=@ALEVL_CODE
where 子句中的行。我想成为类似 when @ALEVL_CODE
is GR
then doGR
和PH
else just do的东西@ALEVL_CODE
。这有道理吗?一些帮助将不胜感激。