create proc UTC_GetMingxiBaobiao
(
@UTC_MingXi_Cust varchar(10),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20)
)
as
select h.*,d.ArtCode,d.Quantity,a.ArtName into #temp
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode)if(@UTC_MingXi_Cust is not null)
delete
from #temp
where CustName != @UTC_MingXi_Custif(@UTC_MingXi_State < 2)
delete
from #temp
where (Flag = @UTC_MingXi_State)if(@UTC_MingXi_date is not null)
delete
from #temp
where (@UTC_MingXi_date != convert(varchar(10),Acctime,120))select *
from #temp
VS2005 托一个DataSet到页面, 然后配置数据集(绑定上面的存储过程)
出现 #temp无效
请求解答
2个月没解决的问题
(
@UTC_MingXi_Cust varchar(10),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20)
)
as
select h.*,d.ArtCode,d.Quantity,a.ArtName into #temp
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode)if(@UTC_MingXi_Cust is not null)
delete
from #temp
where CustName != @UTC_MingXi_Custif(@UTC_MingXi_State < 2)
delete
from #temp
where (Flag = @UTC_MingXi_State)if(@UTC_MingXi_date is not null)
delete
from #temp
where (@UTC_MingXi_date != convert(varchar(10),Acctime,120))select *
from #temp
VS2005 托一个DataSet到页面, 然后配置数据集(绑定上面的存储过程)
出现 #temp无效
请求解答
2个月没解决的问题
如果是临时表,出现 #temp无效 就很正常
怎么又查询select * #temp???
、什么意思啊?删除了临时表,怎么可能再查找出来呢?当然会报临时表出错了啊
Invalid object name '#temp'
参考:http://topic.csdn.net/u/20080515/11/7c22bfc8-d55c-4f92-8e3a-3f6bc2fc9862.html
另外临时表用完在存储过程最后drop掉
from #temp
之后及时删除
drop table #temp
否则第二次条用存储过程时当然会出错了
from dbo.#temp
(
@UTC_MingXi_Cust varchar(10),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20)
)
as
select h.*,d.ArtCode,d.Quantity,a.ArtName into #temp
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode) if(@UTC_MingXi_Cust is not null)
delete
from #temp
where CustName != @UTC_MingXi_Cust if(@UTC_MingXi_State < 2)
delete
from #temp
where (Flag = @UTC_MingXi_State) if(@UTC_MingXi_date is not null)
delete
from #temp
where (@UTC_MingXi_date != convert(varchar(10),Acctime,120)) select *
from #temp
drop table #temp
from #temp
drop table #temp
逻辑上没问题,在查询分析器执行看看
那你直接对select加条件好了,也不用临时表,出这种错误了。
显示创建你的临时表
CREATE TABLE #TEMP
(
COL1 NVARCHAR(400),
....
)
或者你使用表变量,将#换成@,而且必须显示申明关于DROP或不DROP,我认为关系不大,在执行完存储过程后,你的临时表也将被删除
from #temp
之后及时删除
drop table #temp
否则第二次条用存储过程时当然会出错了
如果用全局临时表的话,你告诉当我有若干查询同时进行的时候怎么办?
DATASET是维持连接的???LZ,你把你前面的代码贴出来吧。
(
@UTC_MingXi_Cust varchar(50),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20),
@UTC_MingXi_Accuser varchar(30)
)
asdeclare @temp table
(
UTCid varchar(10),
PhoneNo varchar(20),
CustCode varchar(20),
CustName varchar(50),
Rectime datetime,
Flag int,
Acctime datetime,
Accuser varchar(20),
ArtCode varchar(4),
Quantity int,
ArtName varchar(40)
)insert @temp
select h.UTCid,h.PhoneNo,h.CustCode,h.CustName,convert(varchar(10),h.Rectime,120) as Rectime,
h.Flag,convert(varchar(10),h.Acctime,120) as Acctime,h.Accuser,d.ArtCode,d.Quantity,a.ArtName
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode)if(@UTC_MingXi_Cust is not null)
delete
from @temp
where CustName != @UTC_MingXi_Custif(@UTC_MingXi_State < 2)
delete
from @temp
where (Flag = @UTC_MingXi_State)if(@UTC_MingXi_date is not null)
delete
from @temp
where (@UTC_MingXi_date != convert(varchar(10),Acctime,120))
if(@UTC_MingXi_Accuser is not null)
delete
from @temp
where (@UTC_MingXi_Accuser != Accuser)select *
from @temp使用表变量 可以成功
很疑惑 为什么不能使用临时表 特别谢谢 ViewStates
第一个问题:我只是借指说明局部与全局的区别 具体业务环境需要具体实现 要不试试 你提任何一个方案都会有不适应的特定现实条件
第二个问题:自动维护的持续连接不是你认为的“维持连接” 我当然知道DataSet教材中都会首先提及其“非持续”特性 但看你怎么理解了 客户程序不管理不意味着系统不管理
第三个问题:知识么 广而泛 相互学习自由发表观点 莫要用质问的口气
2.DATASET在取出后,和数据库的连接已经完全断开,维持的只是DATASET中表的关系,而这个地方最后出来的只有一个表,从何谈的上维护?
3.我不是质问的口气,针对问题,找到解决办法,的确没错。但是如果解决办法只能说是掩盖了表面现象或者说可能存在误导,那么你认为这个解决办法正确么?
我以前做东西时也存在类似问题,仅仅是为了解决问题而解决问题,但是这样的后果是东西是出来,老板高兴了,但是自己却根本没有从项目开发中学到任何东西,只是机械式的打字而已。
CSDN中很多人也有这样的问题,仅仅只是为了解决而解决,但是为什么这样可以,那样不行还是不清楚。
你的回复中我感觉有些语句是存在错误或者疏漏的,我只是想提出来,绝没有质问,如有误解,望见谅。
第一问题我就不再申明了 我的回答是针对为什么#temp无效 至于用全局表 物理表 还是继续用临时表是可选项 我有用"或"哦
第二个问题 DataSet可以以离线方式也可以以实时方式操作数据库 我称之为"可自动维护的持续连接" 与各版本教程上用的"非持续"叫法不同 虽然我一直坚持"非持续"的提法不够严密 想了想 还是"非持续"的叫法合适 至少不会偏离大众习惯 感谢指正
第三个问题么 一般回答问题 只要能在本地模仿对方环境的我都是测试完后才发代码 但越是可行的方案越需要时间精力去实现 在需求不够明确客观时间条件不允许的情况下 给个简版说法也是该前提下尽力之为 我好像没说过这是"必须的""最好的"吧呵呵 有N多人回答 会有N多种答案 倘使你的方案够棒 我们自会认同呵呵