我想(綜合)填充以星形模型數據集市空的時間維度表後,它應該是這樣的:加載時間維度表的T-SQL
我使用以下T-SQL代碼爲:
/*
STEP 3
Populate DIM_TIJD table with date and its derrived values data
*/
USE Fuzzy_DM_Robin
--DECLARE DATE VARIABLES FOR DATE PERIOD
DECLARE @StartDate datetime = '01/01/1995'
DECLARE @EndDate datetime = '01/01/2026'
DECLARE @DateInProcess datetime
SET @DateInProcess = @StartDate
WHILE @DateInProcess < = @EndDate
BEGIN
SET NOCOUNT ON
--LOOP THROUGH INDIVIDUAL DATES DEFINED BY TIME PERIOD
INSERT INTO DIM_TIJD (
[DATUM_ID],
[DATUM],
[DAG_VD_WEEK],
[WEEKNR],
[MAAND],
[MAAND_OMSCHRIJVING],
[LAATSTE_DAG_MAAND],
[KWARTAAL],
[JAAR]
)
VALUES (
CAST (@DateInProcess AS numeric (10)),
@DateInProcess,
CONVERT(varchar(10), @DateInProcess, 110) + ', ' + DATENAME(WEEKDAY, @DateInProcess),
DATEPART (wk, @DateInProcess),
MONTH(@DateInProcess),
CAST(YEAR(@DateInProcess) as varchar(4)) + ' - ' + DATENAME(MONTH, @DateInProcess),
DATEPART (dd, EOMONTH (@DateInProcess)),
DATENAME(QUARTER, @DateInProcess),
YEAR(@DateInProcess))
END
儘管如此,它不會加載。我得到的消息是:
消息1:
String or binary data would be truncated
和消息2:
[Execute SQL Task] Error: Executing the query "/* STEP 3 Populate DIM_TIJD table with date and it..." failed with the following error: "The statement has been terminated.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
我在做什麼錯? SSMS中沒有底層指示代碼有問題,我已經檢查了表和代碼中所有的varchar長度是相同的。我曾嘗試與結果集設置擺弄左右,但只給了我另一條消息:
消息3:
[Execute SQL Task] Error: There is an invalid number of result bindings returned for the ResultSetType: "ResultSetType_SingleRow".
預先感謝您!
您好克里斯,感謝您的輸入。不幸的是,它並沒有幫助,同樣的問題仍然存在...任何額外的建議? –
我會首先檢查表中關於數據類型和長度的列 - 數據是否適合表或將被截斷?我建議使用臨時表或表變量來設置場景並查看是否可行。隨意發佈表設計/數據類型在這裏,我會看看。 –