try (did not test, so it might not work)WHILE @@FETCH_STATUS = 0
BEGIN
declare @Y char(01)
declare @chgtabname sysname SET @Y = substring(@chgwo,5,1)
if substring(@chgwo,6,1) > '6'
SET @chgtabname = 'pack0'+@Y+'b_log'
else
SET @chgtabname = 'pack0'+@Y+'b_log'
exec('insert into @tmptab select a.wono,a.partno,a.woqty as woqty,b.okqty from woms a, (select wono,count(*) as okqty from ' + @chgtabname + ' where ispass =1 and rework=0 and wono=''' + @chgwo + ''' and ispass=1 and rework=0 group by wono ) b where a.wono=b.wono') fetch next from chgwo_cursor
into @chgwo
END
BEGIN
declare @Y char(01)
declare @chgtabname sysname SET @Y = substring(@chgwo,5,1)
if substring(@chgwo,6,1) > '6'
SET @chgtabname = 'pack0'+@Y+'b_log'
else
SET @chgtabname = 'pack0'+@Y+'b_log'
exec('insert into @tmptab select a.wono,a.partno,a.woqty as woqty,b.okqty from woms a, (select wono,count(*) as okqty from ' + @chgtabname + ' where ispass =1 and rework=0 and wono=''' + @chgwo + ''' and ispass=1 and rework=0 group by wono ) b where a.wono=b.wono') fetch next from chgwo_cursor
into @chgwo
END
解决方案 »
- 高手看看能不能帮我解决
- 研究一下这道题关于SQL server-side trace.
- dreamwave 连接sql数据库求助
- 2个bcp的简单问题!!!
- 关于数据类型的问题
- 多条记录并为变成一条记录(有点怪)
- 大虾们,帮忙分析下啊~~~
- 一个 Select 问题
- <font color="#FF0000">在 Oracle 中怎样用触发器实现象 Access 一样的自动编号,别掺水,这事很紧急,请给出确实可用的代码,如果试过能行给300分,决不食言</font>
- 没有关联两个表,求一个表在另一个表日期之间的数据合计
- 高手高手高高手(sql问题登峰造极)
- 请讨论‘事务’的合理使用!!!~~~~~~~
into @chgwo
这两句放在你的位置就会跳过第一行记录,象saucer(思归, MS .NET MVP)说的那样改一下试试。
...'insert into @tmptab select ...
会爆出不能识别变量@tmptab
去查查前面的帖子,已经讨论的很详细了。
declare @chgwo nchar(10)
declare @tmptab table (wono char(10),partno char(20),woqty dec,okqty dec)declare chgwo_cursor CURSOR global FOR
select distinct wono from changewo where process = 'pack' and wono like 'WO%'
open chgwo_cursor
fetch chgwo_cursor into @chgwo
WHILE @@FETCH_STATUS = 0
BEGIN
declare @Y char(01)
declare @chgtabname sysname
into @chgwo
SET @Y = substring(@chgwo,5,1)
if substring(@chgwo,6,1) > '6'
SET @chgtabname = 'pack0'+@Y+'b_log'
else
SET @chgtabname = 'pack0'+@Y+'b_log'
exec('insert into @tmptab select a.wono,a.partno,a.woqty as woqty,b.okqty from woms a, (select wono,count(*) as okqty from ' + @chgtabname + ' where ispass =1 and rework=0 and wono=''" + @chgwo + "'
' and ispass=1 and rework=0 group by wono ) b where a.wono=b.wono')
END
fetch chgwo_cursor into @chgwo
CLOSE chgwo_cursor
deallocate chgwo_cursor