SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GET_ACTS_RULES_LIST_FOR_CLIENTS]
(@ACTS_FOR_CLIENTS)
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM DCMREPOSITORYV1..ACTS
WHERE NAME IN (SELECT NAME FROM ACTS_FOR_CLIENTS)
SELECT *
FROM COMPLIANCE_FOR_CLIENTS
WHERE ACTSID IN (SELECT ID
FROM ACTS_FOR_CLIENTS
WHERE NAME IN (SELECT NAME FROM ACTS_FOR_CLIENTS))
ORDER BY COMPLIANCE_CATEGORY_ID, ACTSID
SELECT *
FROM STATE_CENTRAL_RULE_FOR_CLIENTS
WHERE ACTSID IN (SELECT ID
FROM DCMREPOSITORYV1..ACTS
WHERE Name IN (SELECT NAME FROM ACTS_FOR_CLIENTS))
ORDER BY COMPLIANCE_CATEGORY_ID, ACTSID
END
答案 0 :(得分:0)
CREATE PROCEDURE不需要() https://docs.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql +添加类型变量@ACTS_FOR_CLIENTS
USE [TESTING]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GET_ACTS_RULES_LIST_FOR_CLIENTS] @ACTS_FOR_CLIENTS VARCHAR(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SQL VARCHAR(MAX)
SET @SQL = 'SELECT * FROM DCMREPOSITORYV1..ACTS WHERE NAME IN (SELECT NAME FROM '+@ACTS_FOR_CLIENTS+')';
SET @SQL = @SQL + 'SELECT * FROM COMPLIANCE_FOR_CLIENTS WHERE ACTSID IN (SELECT ID FROM ' + @ACTS_FOR_CLIENTS +' WHERE NAME IN (select NAME from ' + @ACTS_FOR_CLIENTS + ')) ORDER BY COMPLIANCE_CATEGORY_ID,ACTSID ';
SET @SQL = @SQL + 'SELECT * FROM STATE_CENTRAL_RULE_FOR_CLIENTS WHERE ACTSID IN (SELECT ID FROM DCMREPOSITORYV1..ACTS WHERE Name IN (select NAME from ' + @ACTS_FOR_CLIENTS +')) ORDER BY COMPLIANCE_CATEGORY_ID,ACTSID';
EXEC(@SQL);
答案 1 :(得分:0)
尝试更正:
CREATE PROCEDURE [dbo].[GET_ACTS_RULES_LIST_FOR_CLIENTS]
@ACTS_FOR_CLIENTS ACTS_FOR_CLIENTS readonly
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM DCMREPOSITORYV1..ACTS WHERE NAME IN (SELECT NAME FROM ACTS_FOR_CLIENTS)
SELECT * FROM COMPLIANCE_FOR_CLIENTS WHERE ACTSID IN (SELECT ID FROM ACTS_FOR_CLIENTS WHERE NAME IN (select NAME from ACTS_FOR_CLIENTS))
ORDER BY COMPLIANCE_CATEGORY_ID,ACTSID
SELECT * FROM STATE_CENTRAL_RULE_FOR_CLIENTS WHERE ACTSID IN (SELECT ID FROM DCMREPOSITORYV1..ACTS WHERE Name IN (select NAME from ACTS_FOR_CLIENTS))
ORDER BY COMPLIANCE_CATEGORY_ID,ACTSID
END
更正:
无效的声明用户定义表@ACTS_FOR_CLIENTS