任何人都可以告诉我为什么我的行语法错误不正确
SELECT * INTO @pre_and_post_op FROM NBOCAP(@StartDate,@EndDate,@OrgCode)
代码:
DECLARE @StartDate datetime
DECLARE @EndDate datetime
DECLARE @OrgCodeString varchar (8000)
SET @StartDate = '01-JAN-11'
SET @EndDate = '31-MAR-14'
SET @OrgCodeString = 'RA720|RQ801|RVJ20|RN325|8AAAA|RBA11'
DECLARE @i int
DECLARE @OrgCode varchar(10)
DECLARE @OrgCount int
DECLARE @TrustTable TABLE
(idx int IDENTITY(1,1), org varchar(10))
DECLARE @pre_and_post_op TABLE
(CARE_ID int,ERR_NumberOfNodesPositive int,ERR_FinalPathologyTCategory int,
ERR_FinalPathologyNCategory int,ERR_FinalMCategory int)
INSERT INTO @TrustTable
SELECT * FROM SplitString(@OrgCodeString, '|')
SET @i = 1
SET @OrgCount = (SELECT COUNT(*) FROM @TrustTable)
IF @OrgCount > 0
WHILE (@i <= @OrgCount)
BEGIN
SET @OrgCode = (SELECT org FROM @TrustTable WHERE idx = @i)
SELECT * INTO @pre_and_post_op FROM NBOCAP(@StartDate,@EndDate,@OrgCode)
SET @i = @i + 1
END
答案 0 :(得分:3)
你不能SELECT INTO
一个表变量。引用MSDN:
您不能将表变量或表值参数指定为新表。
使用INSERT INTO ... SELECT
代替
INSERT INTO @pre_and_post_op SELECT * FROM NBOCAP(@StartDate,@EndDate,@OrgCode)