元数据不一致解决的一个实例
发表于:2007-07-02来源:作者:点击数:
标签:
存储过程如下: ALTER procedure d_sel_bj_xcl @filter varchar(2000),@sortstr varchar(2000),@iskw bit as set @sortstr=@#spzyflid,spkw,spid@# declare @sql varchar(8000) set @sql=@# select spid,ckid,spmc,spgg,czmc,bzmc,cdmc,zlmc,spjldw,spkw,@# if
存储过程如下:
ALTER procedure d_sel_bj_xcl
@filter varchar(2000),@sortstr varchar(2000),@iskw bit
as
set @sortstr=@#spzyflid,spkw,spid@#
declare @sql varchar(8000)
set @sql=@#
select spid,ckid,spmc,spgg,czmc,bzmc,cdmc,zlmc,spjldw,spkw,@#
if @iskw=1
set @sql=@sql+@#kwh,@#
set @sql=@sql+@#
sum(case when a.crklbfx=1 then sl else -sl end) as spxcl from (
select a.*,b.spzyflid,b.spmc,b.spgg,cz.czmc,bz.bzmc,cd.cdmc,zl.zlmc,b.spjldw,
spkw=case when patindex(@#@#%([0-9][0-9][0-9][0-9])@#@#,b.spmc)>0
then right(spmc,6) else @#@#@#@# end,
c.crklbfx from bjlsb a
join crklb c on a.crlb=c.crklbid
left join sp b on a.spid=b.spid
left join cz on b.spczid=cz.czid
left join bz on b.spbzid=bz.bzid
left join zl on b.spzlid=zl.zlid
left join cd on b.spcdid=cd.cdid
where a.iszf is null @#
if len(@filter)>0
set @sql=@sql+@# and @#+@filter
set @sql=@sql+@#) a
group by spid,spzyflid,ckid,spmc,spgg,czmc,bzmc,cdmc,zlmc,spjldw,spkw@#
if @iskw=1
set @sql=@sql+@#,kwh@#
if len(@sortstr)>0
set @sql=@sql+@# order by @#+@sortstr
exec(@sql)
调用的过程如下:
select * from
openrowset(@#sqloledb@#,
@#jszg@#;@#sa@#;@#6162900@#,
@#execute zgerp..d_sel_bj_xcl @#@#ckid=@#@#@#@#45@#@#@#@#@#@#,@#@#@#@#,0@#) as a
结果为:
服务器: 消息 7355,级别 16,状态 1,行 1
OLE DB 提供程序 @#sqloledb@# 为列提供的元数据不一致。执行时更改了名称。
OLE DB 错误跟踪[Non-interface error: OLE DB provider returned different names for a column: ProviderName=@#sqloledb@#, CompileTimeColumnName=@#kwh@#, RunTimeColumnName=@#spxcl@#, Rowset=execute zgerp..d_sel_bj_xcl @#ckid=@#@#45@#@#@#,@#@#,0]。
仔细看一下就可以看到kwh列的存在,如果使用库位管理,那么,库位号就是一个汇总的依据,但查询时设为0,这和编译产生的列不同,编译产生所有的列,所以就出现了这个错误,实在想不出什么好办法,就将查询时将0设为1,反正不使用库位来管理,得出的数是不受影响的:)
原文转自:http://www.ltesting.net