0
我想從我的複選框列表中選擇的值,但我一直在sql中遇到錯誤。未封閉的報價
錯誤
Msg 105, Level 15, State 1, Line 22
Unclosed quotation mark after the character string ')'.
Msg 102, Level 15, State 1, Line 22
Incorrect syntax near ')'.
SP
@DEPTCODE INT,
@COA VARCHAR(50),
@MAP VARCHAR(10)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SQL VARCHAR(MAX);
BEGIN
SET @SQL = N'SELECT
A.GL_EXCEPT_ID AS ''GL ID''
, A.COA_SYSTEM AS ''Account Type''
, A.ENTN AS ''Entity''
, A.MED_CTR AS ''Medical Center''
, (''['' + A.LOCN + ''] '' + B.LOCN_DESC) AS ''Location Code''
, (''['' + A.CTRN + ''] '' + C.CTRN_DESC) AS ''Cost Center''
, (''['' + RTRIM(A.FUND) + ''] '' + A.FUND_DESC) AS ''Fund''
, A.ROLLUP_TYPE_ID AS ''Rollup ID''
, A.ROLLUP_TYPE_DESC AS ''Rollup Type''
, A.MAPPING AS ''Mapping''
FROM V_ROLLUP_GL_DESC_REV1 A
LEFT JOIN T_ROLLUP_GL_LOCN B
ON A.LOCN = B.LOCN
AND A.MED_CTR_ID = B.MED_CTR_ID
AND A.COA_SYSTEM = B.COA_SYSTEM
LEFT JOIN T_ROLLUP_GL_CTRN C
ON A.CTRN = C.CTRN
AND A.COA_SYSTEM = C.COA_SYSTEM
WHERE (A.DEPT_ID = '+CONVERT(VARCHAR,@DEPTCODE)+')
AND A.COA_SYSTEM IN ('[email protected]+')
AND A.MAPPING IN ('[email protected]+''')'
PRINT(@SQL)
EXEC(@SQL)
END
END
查詢
USE [Rollup2]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[USP_GET_GL_BY_DEPT]
@DEPTCODE = 1000,
@COA = N'''COA'',''COA_SYSTEM''',
@MAP = N'''DEFAULT'',''EXCEPTION'''
SELECT 'Return Value' = @return_value
謝謝秒。我看到問題是VARCHAR長度。最初有單引號,並且由於錯誤而改變了它。 – user1512593 2012-08-13 23:35:38