易截截图软件、单文件、免安装、纯绿色、仅160KB

表变量,动态sql - MS-SQL Server / 疑难问题

sql2005 声明表变量
 declare @t_tablebarcode table(id int) ,barcode varchar(50) 
,PackLayer int,SubTypeID int,PkgRatioID int
,ResCodeID int,ImportID int 
,DeActiveID int ,ActiveID int)
动态sql
set @t_SQL='insert into '+@tarGet+'(Barcode,rescodeid,importid,printid,activeid)
select barcode,rescodeid,importid,null,@p_cActiveID from 
tbarcodeimport where BARCODE in(select barcode from '+@t_tablebarcode+')'
exec @t_SQL
编译出错
消息 137,级别 15,状态 2,过程 ExportSubBarcode,第 26 行
必须声明标量变量 "@t_tablebarcode"。


用實表吧


set @t_SQL ='insert into '+@t_tablebarcode+' select top '+ @p_iCurCodeNum 
+'from tbarcodeimport where rescodeid='+@p_iLevelID+'order by id'

刚刚写错了,2楼的是那个动态的sql

得用临时表

create table #t_tablebarcode (id int) 


set @t_SQL='insert into '+@tarGet+'(Barcode,rescodeid,importid,printid,activeid)
select barcode,rescodeid,importid,null,@p_cActiveID from  
tbarcodeimport where BARCODE in(select barcode from #t_tablebarcode)'

现在不想用全局临时表和实表

用临时表吧...

SQL code:


set @t_SQL='declare @t_tablebarcode table(id int
,barcode varchar(50)
,PackLayer int,SubTypeID int,PkgRatio


相关问答:

求一sql语句 - MS-SQL Server / 疑难问题

现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

关于Vb中sql语句的写法(100分) - Java / Web 开发

求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......

mysql区没高手 - MS-SQL Server / 基础类

我觉得mysql和sqlserver有共同的地方:
有个问题是关于表的锁问题:
进程A 进程B
select * from user where id in lock share mode(共享锁)
&nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号