查询应输出特定的项目列表,以及商店信息和经理信息等信息。使用光标翻阅各种不同管理级别的列表,选择相关信息,然后通过电子邮件向该人员发送查询为其地区/地区/商店返回的内容。
我的问题是旅程中的 SSIS 阶段。尽管代码的行为就像它在运行一样,但如果我单独运行 Itemdata.dtsx (以便查看错误),它会抛出错误:
“警告:组件“Sources-ItemData”(1) 的外部列与数据源列不同步。需要从外部列中删除外部列“RM_Email”(49)。外部列“SM_Email” “需要从外部列中删除 (46)。需要从外部列中删除外部列“DM_Email”(43)。”
这会导致 SQL Server Mngt Studio 说它已运行,但电子邮件的内容只是表头;没有数据,并且无论我做什么,表标题都不会改变。
我已经从我的源代码(下面发布)及其使用的表中删除了这些列。我缺少什么?
BEGIN
SET NOCOUNT ON;
DECLARE @ProcedureName varchar(255)
DECLARE @ExportFolder varchar(255)
DECLARE @TempFolder varchar(255)
DECLARE @WarningLevel varchar(255) = 'log'
DECLARE @MsgDescription varchar(2000) = ''
DECLARE @RecordCount int = 0
DECLARE @ReportDate date = getdate()
DECLARE @Begdate date = convert(date,(dateadd(month,-1,getdate())))
DECLARE @Enddate date = convert(date,(dateadd(day,-1,getdate())))
DECLARE @Siteid int
DECLARE @Subject varchar(75) = ''
DECLARE @Body varchar(50) = ''
DECLARE @RMLastName varchar(25)
DECLARE @RMFirstName varchar(25)
DECLARE @RegionKey int
DECLARE @DistrictKey int
DECLARE @Email varchar(50)
BEGIN TRY
--Table used as data source for each pass
Truncate Table Example.dbo.itemdata
--Send reports to Regional Managers by building Cursor RMListCursor,
--then running SELECT statement against each name (using @RMLastName and @RMFirstName to discern),
--then emails results of SELECT statement to that Regional Manager.
--Goes through CursorList, then ends.
BEGIN
--Set cursor for RM Email; returns all regional managers.
DECLARE RMListCursor CURSOR FOR
SELECT distinct t.lastname, t.firstname, t.Email
FROM Example.[dbo].[tblUser] t
JOIN example.dbo.vStoreDistrictRegionActive vs
ON t.LastName = vs.RMLastName and t.FirstName = vs.RMFirstName
ORDER BY LastName
OPEN RMListCursor
FETCH NEXT FROM RMListCursor
INTO @RMLastName
, @RMFirstName
, @Email
WHILE @@FETCH_STATUS = 0--(@SetInt < 6)
BEGIN
Truncate table Example.dbo.itemdata
--Builds data, then inserts into Table built for this query. Note that there is no mention of DM_EMAIL, RM_EMAIL, or SM_EMail anywhere.
INSERT INTO Example.dbo.itemdata
SELECT InvoiceNumber,
shipFROMid,
ad.SiteId,
MfrCode,
PartCode,
UnitNetCore,
ad.QuantityShipped,
ShipDate,
--First/Last Name of this item's store's District Manager.
rtrim(substring((SELECT ISNULL(DMfirstName,'') FROM example.dbo.vSiteRegionDistrictActiveV2 dm WHERE ad.siteid = dm.SiteNumber),1,30)) + ' ' +
substring((SELECT ISNULL(DMLastName,'') FROM example.dbo.vSiteRegionDistrictActiveV2 dm WHERE ad.siteid = dm.SiteNumber),1,30) DM
--This is where DM_EMAIL, RM_EMAIL, and SM_EMail originally were before they were removed from both here and .ItemData.
FROM example.dbo.vInvoiceHeaderDetail_Adis ad
join example.dbo.Site ss on ad.SiteId=ss.siteid
join example.dbo.vStoreDistrictRegionActive vs on ad.SiteId = vs.SiteId
WHERE ad.siteid is not null and UnitNetCore>=250 and SUBSTRING(InvoiceNumber,2,1)='D' and QuantityShipped>0
and isactive=1 and isowned=1
and ShipDate between @Begdate and @Enddate
and vs.RMFirstName = @RMFirstName
and vs.RMLastname = @RMLastName
ORDER BY ad.SiteId,ShipFROMID,shipdate
-- Execute SSIS package which downloads table to d: for email.
set @RecordCount=@@ROWCOUNT
--Quick check so that if the results were blank, don't bother sending a blank email.
IF @RecordCount<>0
BEGIN
set @Subject = 'Cores billed from PWI >= $250 ' + cast(CONVERT(date,GETDATE()) as varchar(12))
set @Body = 'Run date/time- ' + cast(GETDATE() as CHAR(20))
EXEC xp_cmdshell 'd:\"Program Files (x86)"\"Microsoft SQL Server"\100\DTS\Binn\DTexec.exe /f "D:\etl\bulk\ssis\Misc\ItemInfo.dtsx"'
EXEC msdb.dbo.sp_send_dbmail
@profile_name ='SQL Mail',
@recipients ='test', --@email
@subject = @Subject,
@body = @Body,
@body_format = 'HTML',
@File_attachments = 'D:\export\temp\ItemInfo.xls',
@attach_query_result_as_file =0,
@query_attachment_filename='\ItemInfo.xls',
@query_result_width = 500
END
--Brings CURSOR back up to next name on List, repeats process.
FETCH NEXT FROM RMListCursor
INTO @RMLastName
, @RMFirstName
, @Email
END
END
CLOSE RMListCursor
DEALLOCATE RMListCursor
END TRY
BEGIN CATCH
SET @WarningLevel = 'error'
SET @MsgDescription = 'SQL Err= [' + CAST(ERROR_MESSAGE() as varchar(200)) + ' (' + CAST(ERROR_LINE() as varchar) + ')]'
EXEC example.dbo.spAddSysMessage 'Store Aging', @WarningLevel , @ProcedureName , '', 'EOM Store Aging Report', @RecordCount
END CATCH
END
您最近似乎正在更改 OLEDB 源或其他类型的源。
因此,您必须删除 OLEDB Source 并重新创建一个新的。然后还删除特定字段的映射,保存,再次返回映射并将其映射回来。比它应该工作得好。
而不是删除并重新创建:
我也遇到了同样的问题,我的所有列名称都相同,但仍然收到“‘excelName’的外部列与数据源列不同步。需要将列“mycolname”添加到外部列。 列“F62”需要添加到外部列中。” 我也验证了很多次,但没有运气,即使我将我的列标题与目标表以及Excel公式中的目标表相匹配,并且所有似乎都是正确的。因此,我手动一一列检查,最后发现我用于我的文件连接最初的第一个字母是大写的 "Mycolname" ,作为我正在使用的文件(我曾经覆盖源文件),我只是粘贴了来自其他文件的数据,由于我的标题发生了变化。我再次更改了输入文件的标题并且它起作用了。
注意:使用 SSIS 时要小心...真的很危险。
我意识到这是一个较旧的问题,但我有一个 458 列宽的文本文件。叹。重置列等可能很乏味,在这种情况下,我只有一列在平面文件连接管理器中进行配置后更新。数据类型长度显示为 13,并在同步到显示长度为 12 的数据源时发出警告。
这就是我所做的,因为我不想重置列,并且其他方法都不起作用或会给我带来太多的心痛/浪费时间:
在 Visual Studio 中关闭项目。
保存项目的副本,以防您误操作。
在 NotePad++ 等工具中打开项目文件
我在项目中搜索了平面文件源字符串。这是为了获取下一步要搜索的内容的模板。
在我的例子中,连接管理器平面文件数据源已配置,如下所示:
Package\Import Data\Flat File Source.Outputs[Flat File Source Output].Columns[MyColumn_1a]
现在,使用该模板搜索有问题的列:
Package\Import Data\Flat File Source.Outputs[Flat File Source Output].Columns[MyColumn_238b]
查看长度(在我的情况下,属性报告不同步)并进行相应更新。
refId="Package\Import Data\Flat File Source.Outputs[Flat File Source Output].Columns[EXAMT_1]"
codePage="1252"
dataType="str"
errorOrTruncationOperation="Conversion"
errorRowDisposition="FailComponent"
externalMetadataColumnId="Package\Import Data\Flat File Source.Outputs[Flat File Source Output].ExternalColumns[EXAMT_1]"
length="12" <<<----- UPDATED THIS FROM 13 TO 12
lineageId="Package\Import Data\Flat File Source.Outputs[Flat File Source Output].Columns[EXAMT_1]"
name="EXAMT_1"
truncationRowDisposition="FailComponent">
<properties>
<property
dataType="System.Boolean"
description="Indicates whether the column uses the faster, locale-neutral parsing routines."
name="FastParse">false</property>
<property
dataType="System.Boolean"
description="Indicates whether the data is in binary format."
name="UseBinaryFormat">false</property>
</properties>
</outputColumn>```
保存文件(在 NotePad++ 中),然后关闭文件。
在 Visual Studio 中打开文件并检查是否有错误。