某个编号在某段时间某个仓库的入库统计

declare @storeid nvarchar(2)
  declare @prdtid nvarchar(10)
  declare @start nvarchar(20)
  declare @end nvarchar(20)
  declare @inno nvarchar(20)
  declare @strSql nvarchar(4000)
  declare @tempno nvarchar(4000)
  set @storeid='01'
  set @prdtid='0230157'
  set @start='2012-03-21 12:00'
  set @end='2012-03-25'
  declare innoCursor cursor for
 select siid from [szjdw_log].[dbo].[mf_prdtin] where  createdt>@start and createdt<@end and storeid=@storeid
  open innoCursor
  fetch innoCursor into @inno
  while @@FETCH_STATUS=0
  begin
 if @tempno is null
 begin
 set @tempno=''''+ltrim(rtrim(@inno))+''''
 end
 else
 begin
 set @tempno=@tempno+','''+ltrim(rtrim(@inno))+''''
 end
  fetch next from innoCursor into @inno
  end
  close innoCursor
  deallocate innoCursor

  IF OBJECT_ID('Tempdb.dbo.#S') Is Not Null
  begin
 print 'Exists Table Tempdb.dbo.#S'
 drop table #S
  end
  Else
  begin
 print 'Not Exists Table Tempdb.dbo.#S'
 create table #S(
  [siid] [char](10) NOT NULL,
  [prdtid] [char](7) NOT NULL,
  [num] [float] NULL,
  [price] [float] NULL,
  [seq] [int] NULL
 )
  end
  delete from #S
  set @strSql=N'select * from mf_prdtin_de where siid in ('+ltrim(rtrim(@tempno))+') and prdtid='''+@prdtid+''''
  select @strSql
  --insert into #S exec(@strSql)
  --select * from #S
  go

 

posted @ 2012-03-23 18:25  szjdw  阅读(152)  评论(0编辑  收藏  举报