任何一個可以幫助我從解決這個Dynamic query
到Static one
轉換動態SQL靜態SQL
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
感謝您的有價值的解決方案這是工作。 – Prabhavith 2012-07-25 03:17:55