有人可以帮我摆脱这个错误吗?
第15行,第15行,第1行,第12行 关键字' INTO'附近的语法不正确。 Msg 102,Level 15,State 1,Line 24 ' LocationID'附近的语法不正确。
use DB1
-- Declare variables
declare @AnalysisSID varchar(10)
declare @ExposureDB varchar(250)
declare @AnalysisName varchar(250)
-- !! begin user input !! -------------------------------------------------------------------
set @AnalysisSID =9
set @ExposureDB = (select ExposureDataSourceName
from t9_LOSS_DimExposureDataSource) --<--!!! update result table number
-- !! end user input !! ----------------------------------------------------------------------
set @AnalysisName = (select AnalysisName from tAnalysisResult where ResultSID = @AnalysisSID)
Exec(
'
if not (exists (select * from sysobjects where name = ''LOSSES_FORFEED''))
begin
CREATE TABLE LOSSES_FORFEED (
Name varchar(250) NOT NULL,
LOCID varchar(100) NOT NULL,
ContractID varchar(100) NOT NULL,
GroundUp_Loss float,
Gross_Loss float)
end
INTO LOSSES_FORFEED
SELECT
'''+@AnalysisSID+''' as AnalysisID, '''+@AnalysisName+''' as Name,
l.LocationID as LOCID,
c.ContractID,
sum(GroundUpLoss) as GroundUp_Loss,
sum(GrossLoss) as Gross_Loss
FROM t'+@AnalysisSID+'_LOSS_ByLocationSummary loss
join '+@ExposureDB+'..tLocation l on loss.LocationSID = l.LocationSID
join '+@ExposureDB+'..tContract c on l.ContractSID = c.ContractSID
group by
c.ContractID,
l.LocationID
')
答案 0 :(得分:0)
您是否尝试在INSERT
之前添加INTO LOSSES_FORFEED
:
INSERT INTO LOSSES_FORFEED
这应该有效 - 至少对于MS SQl服务器数据库而言。但是参数的数量也不匹配:表LOSSES_FORFEED
有5列,但在select语句中你提供了6个参数。