找了很多资料 但没有讲的很清楚的 因为我的临时表字段是不固定的 所以必须使用临时表 希望各位不吝赐教
解决方案 »
- C# System.Drawing.Text.AddMemoryFont 内存字体
- 求post 方式的发送字符串形式!!
- C# 函数的入参能传一个类对象吗?
- 切换用户遇到的问题
- C# 有 vb 的 With语句吗
- 代码设置windows 2003中的文件属性
- 在WINFORM程序中,怎么将EXCEL导到DATASET中。。急。。谢谢
- 如果要在整个应用程序关闭时修改数据库的数据该写在哪?
- 服务端定义一个缓冲区,客户端发送数据,写入服务端的缓冲区。缓冲区写满了就写入磁盘,清空缓冲区,那么这个缓冲区应该定义成什么?
- C#调用语音库问题,求大神!!!
- 救急,blob图片读出问题
- 关于值类型的内存占用问题,请帮忙给个专业的回答,一直困惑!
create proc rkreport
(
@starttime varchar(10),
@endtime varchar(10)
)
as
select rkname,rktype,sum(rkcount) as rkcount into #temprkreport from ccprk where rktime between convert(datetime,@starttime) and convert(datetime,@endtime) group by rkname,rktype
exec ('alter table #temprkreport add tempid int identity(1,1)')
exec ('alter table #temprkreport add rkggxh nvarchar(3600)')
update #temprkreport set rkggxh=''
declare @RowCount int
select @RowCount=max(tempid) from #temprkreport
declare @rkname varchar(100)
declare @rktype varchar(100)
declare @tempstr nvarchar(3600)
while(@RowCount>0)
begin
select @rkname=rkname,@rktype=rktype from #temprkreport where tempid=@RowCount
set @tempstr=''
select @tempstr=@tempstr+rkggxh+',' from ccprk where rktime between convert(datetime,@starttime) and convert(datetime,@endtime) and rkname=@rkname and rktype=@rktype
update #temprkreport set rkggxh=@tempstr where tempid=@RowCount
set @tempstr=''
set @RowCount=@RowCount-1
end
insert into #temprkreport(rkname,rktype,rkggxh,rkcount) select '合计' as rkname,'--','--',sum(rkcount) as rkcount from #temprkreport
select rkname as 产品名称,rktype as 产品类型,rkggxh as 规格型号, rkcount as 数量 from #temprkreport order by rkcount
go
command.Fill(ds, "ds");调用使得这个方法Fill之前看数据库里 临时表是存在的 一旦Fill之时临时表消失,并抛出异常
临时表如果是你通过语句
比如:
select * into #temptable from 你的表那么这个临时表在SQL server服务重启之前一直存在如果你是存储过程创建的,
比如2楼,当存储过程调用完后,临时表也就消失了这是临时表的基制
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
finally
{
connection.Close();
}
return ds;
}
我使用的这个方法调用临时表 按官方写的全局临时表只要有连接就不会消失的,可是调用的时候会提示临时表不存在
使用全局临时表的原因是多处调用临时表,我如果每次调用都重新添加一次临时表,这样会不会好一些呢不一定,看你用的多少了,一般都是用的时候再创建
如果是在SQL里执行的那么会保存.等服务重新后才消失.
例如:create proc testProc
(
)
as
select id from tableOne where name=名字用参数传递
select .....
update .....
insert into ....go