任何人都可以帮助我吗?我收到了语法错误" Msg 102,Level 15,State 1,Line 26语法不正确' ='。"
{Insert Into [Mortgage_CDriveDW].[dbo].[Dim_LoanX]
([Loan_ID],
[LoanDate],
[LoanYear],
[LoanMonth],
[LoanWeek])}
{Select Distinct
[Loan_ID] = CAST(ISNULL([Loan_ID], -1) As Int),
[LoanDate] = CAST(ISNULL([LoanDate], '01/01/1900') As Date),
CONVERT(INT,DATEPART(YEAR,[LoanDate])) As [LoanYear] = CAST(ISNULL(CONVERT(INT,DATEPART(YEAR,[LoanDate])) As [LoanYear] -1) As Int),
CONVERT(INT,DATEPART(MONTH,[LoanDate])) As [LoanMonth] = CAST(ISNULL(MONTH,[LoanDate], -1) As Int),
CONVERT(INT,DATEPART(WEEK,[LoanDate])) As [LoanWeek] = CAST(ISNULL(WEEK,[LoanDate], -1) As Int)
From [dbo].[ODS]}
{SET IDENTITY_INSERT [Mortgage_CDriveDW].[dbo].[Dim_LoanX] ON
GO
Insert Into [Mortgage_CDriveDW].[dbo].[Dim_LoanX]
( [Loan_Key],
[Loan_ID],
[LoanDate],
[LoanYear],
[LoanMonth],
[LoanWeek]
)
Select -1, -1, -1, -1, -1
SET IDENTITY_INSERT [Mortgage_CDriveDW].[dbo].[Dim_LoanX] OFF
GO}
我还尝试使用Set Identity_Insert ON / OFF在插入和尺寸加载期间考虑空值。 ODS表将LoanYear / Month / Week作为空值,我使用convert和datepart在列中插入值。这是插入加载到Dim_LoanX表时抛出错误的地方。
答案 0 :(得分:1)
这样的行是无效的语法
CONVERT(INT,DATEPART(YEAR,[LoanDate])) As [LoanYear] = CAST(ISNULL(CONVERT(INT,DATEPART(YEAR,[LoanDate])) As [LoanYear] -1) As Int)
有两种语法可用于在查询中定义列
1 AS Col1
或 Col1 = 1
你们俩都有