谁能帮我解决这个Dynamic query
问题Static one
DECLARE @REPCD VARCHAR(10)
SET @REPCD='CA%'
IF (CHARINDEX('*',@REPCD,1)>0 OR CHARINDEX('%',@REPCD,1)>0)
BEGIN
SET @WHERE = ' AND REP_CD like ''' + REPLACE(@REPCD, '''', '') + ''''
END
ELSE
BEGIN
SET @WHERE = ' AND REP_CD = ''' + REPLACE(@REPCD, '''', '') + ''''
END
我想将上面的查询转换成这样的
SELECT * FROM REP
WHERE CASE WHEN CHARINDEX('%',@REPCD,1)>0 THEN REP_CD like 'CA%' END AS REP_CD