我尽我所能环顾网络,但这个问题让我望而却步。我在 SSIS 中有一个可以正常工作的存储过程。它做了很多事情,最终返回了一些数字和文本。该过程本身使用 #temp 表,因为数据不需要存在于 proc 运行之外并返回约 931K 行。
下一步是将proc的输出导入excel。使用 MS 查询,我调用包含必要参数的 proc。它运行但我得到的唯一数据是带有数字的列。我缺少文本值。我认为这可能是从 SSIS 到 Excel 的文本翻译问题,所以我将输出从 nvarchar 更改为 varchar,问题仍然存在。我编写了proc,所以我可以进行任何必要的更改。另外,我认为这可能是一个临时表问题,所以我尝试构建一个表,使用 proc 在其中插入数据,然后将该表拉入 Excel,虽然我得到了更多的文本列,但数字仍然是空白的。
有什么建议吗?
问题的简短版本:SQL 在管理工作室中工作,但文本未返回到 Excel。当完成导入/更新时,proc 中的行数与 Excel 中的行数匹配。数字按预期返回。
版本:
Excel:2007 - SQL Server:2005 - Management Studio:2008R2 - 使用 MS 查询的 ODBC 连接 -
USE [cmdb]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [estimate].[sp_calendar](
@calendar_start char(8),
@years as int
)
as
set nocount on;
declare @calendar_end char(8)
declare @actual_start_date datetime
declare @actual_end_date datetime
declare @loop_counter datetime
set @actual_start_date = CONVERT (datetime, @calendar_start, 112)
set @loop_counter = @actual_start_date
set @actual_end_date = dateadd(year,+@years,@actual_start_date)
set @calendar_end = cast(year(@actual_end_date) as char(4))+RIGHT('00'+ CONVERT(VARCHAR,month(@actual_end_date)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(@actual_end_date)),2)
begin
create table #calendar (
[yearmonth] nvarchar(8)
)
end
begin
create table #results (
[actual ExpectedActionDt] datetime
,[calc ExpectedActionDt] ntext
,ExpectedActionDt datetime
,[calc IntegratedReleasePlanDt] ntext
,IntegratedReleasePlanDt datetime
,[key] ntext
,projectid ntext
,projectnm ntext
,ParentChaseProjectNo ntext
,VersionTag ntext
,itemid ntext
,Qty float
,ItemNotes ntext
,CashflowType ntext
,frequency ntext
,UnitPrice float
,[cost] float
)
end
begin
create table #baseline (
[actual ExpectedActionDt] datetime
,[calc ExpectedActionDt] nvarchar(8)
,ExpectedActionDt datetime
,[calc IntegratedReleasePlanDt] nvarchar(8)
,IntegratedReleasePlanDt datetime
,[key] ntext
,projectid ntext
,projectnm ntext
,ParentChaseProjectNo ntext
,VersionTag ntext
,itemid ntext
,Qty float
,ItemNotes ntext
,CashflowType ntext
,frequency ntext
,UnitPrice float
,[cost] float)
end
insert into #calendar (
[yearmonth])
select
distinct calendarid [yearmonth]
from
[cmdb_core].[dbo].[Calendar]
where
calendarid between @calendar_start and @calendar_end
insert into #baseline (
[actual ExpectedActionDt]
,[calc ExpectedActionDt]
,ExpectedActionDt
,[calc IntegratedReleasePlanDt]
,IntegratedReleasePlanDt
,[key]
,projectid
,projectnm
,ParentChaseProjectNo
,VersionTag
,itemid
,Qty
,ItemNotes
,CashflowType
,frequency
,UnitPrice
,[cost])
select
case
when (ExpectedActionDt is not null)
then ExpectedActionDt
when (IntegratedReleasePlanDt is not null)
then IntegratedReleasePlanDt
else
DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0)
end [actual ExpectedActionDt]
,case
when (ExpectedActionDt is not null)
then cast(year(ExpectedActionDt) as char(4))+RIGHT('00000'+ CONVERT(VARCHAR,month(ExpectedActionDt)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(ExpectedActionDt)),2)
when (IntegratedReleasePlanDt is not null)
then cast(year(IntegratedReleasePlanDt) as char(4))+RIGHT('00000'+ CONVERT(VARCHAR,month(IntegratedReleasePlanDt)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(IntegratedReleasePlanDt)),2)
else
cast(year(getdate()) as char(4))+'0101'
end [calc ExpectedActionDt]
,ExpectedActionDt
,cast(year(IntegratedReleasePlanDt) as char(4))+RIGHT('00'+ CONVERT(VARCHAR,month(IntegratedReleasePlanDt)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(IntegratedReleasePlanDt)),2) [calc IntegratedReleasePlanDt]
,IntegratedReleasePlanDt
,cast(ModelEstimateId as nvarchar(max))+cast(BucketId as nvarchar(max))+cast(ItemNo as nvarchar(max)) [key]
,projectid
,projectnm
,ParentChaseProjectNo
,VersionTag
,itemid
,Qty
,ItemNotes
,CashflowType
,frequency
,UnitPrice
,case
when frequency = 'OneTime'
then Qty
else
cast(round((UnitPrice*Qty)/12,0) as int)
end [cost]
from
estimate.ComputedEstimates
where
[status] <> 'Hold'
and CostCategory <> 'Assembly'
and includeinforecast = 'Y'
and case
when (ExpectedActionDt is not null)
then cast(year(ExpectedActionDt) as char(4))+RIGHT('00000'+ CONVERT(VARCHAR,month(ExpectedActionDt)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(ExpectedActionDt)),2)
when (IntegratedReleasePlanDt is not null)
then cast(year(IntegratedReleasePlanDt) as char(4))+RIGHT('00000'+ CONVERT(VARCHAR,month(IntegratedReleasePlanDt)),2)+RIGHT('00'+ CONVERT(VARCHAR,day(IntegratedReleasePlanDt)),2)
else
cast(year(getdate()) as char(4))+'0101'
end >= @calendar_start
WHILE (@loop_counter <= @actual_end_date)
BEGIN
insert into #results (
[actual ExpectedActionDt]
,[calc ExpectedActionDt]
,ExpectedActionDt
,[calc IntegratedReleasePlanDt]
,IntegratedReleasePlanDt
,[key]
,projectid
,projectnm
,ParentChaseProjectNo
,VersionTag
,itemid
,Qty
,ItemNotes
,CashflowType
,frequency
,UnitPrice
,[cost])
select * from #baseline where [actual ExpectedActionDt] >= @loop_counter
set @loop_counter = dateadd(day,+1,@loop_counter)
END
select
c.[yearmonth]
,a.[calc ExpectedActionDt]
,a.[key]
,a.projectid
,a.projectnm
,a.ParentChaseProjectNo
,a.VersionTag
,a.itemid
,a.ItemNotes
,a.CashflowType
,a.frequency
,a.Qty
,a.UnitPrice
,a.[cost]
from
#calendar as c
left outer join
#results a
on c.[yearmonth] = a.[calc ExpectedActionDt]
order by 1,2,3
drop table #baseline
drop table #results
drop table #calendar