我正在尝试从我的复选框列表中提取选定的值,但我一直在 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 ('+@COA+')
AND A.MAPPING IN ('+@MAP+''')'
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