日期:2014-05-18  浏览次数:20606 次

在存储过程中如何使用ntext类型
=========我的存储过程如下==============
create   procedure   TenancyDynamicRpt
  @DyDate   nvarchar(10),
  @DvKindID   int
as
  --变量定义
  --存放单位ID信息
  declare   @defUnitID   int
  --存放单位名称
  declare   @defUname   nvarchar(256)
  --存放动态查询语句
  declare   @MySQL   nvarchar(4000)
  --定义变量存放单位的数量
  declare   @defUnitSum   int
  --定义变量存放状态的数量
  declare   @defStatSum   int
  --定义变量存放性质的数量
  declare   @defCharSum   int
  set   nocount   on

  --初始化变量
  set   @MySQL= ' '

  --所有单位刻号的所有设备
  select   1   as   StockSign,c.funitid   as   funitid,a.fitemid   as   fitemid,1   as   fqty
    into   #Tmp01   from   ks_item   a
    inner   join   ks_facetcodeentry   b   on   b.finterid=a.finterid   and   b.fentryid=a.fentryid   and   a.faentryid=0
    inner   join   ks_facetcode   c   on   c.finterid=b.finterid
    where   c.fdate <=@DyDate
        and   b.fkindid=@DvKindID
        and   not   b.FStatuID   in(0,1000)
        and   c.funitid   in(select   fitemid   from   ks_item   where   fitemclassid=3   and   fparentid=0)

  --所有出租的设备
  select   2   as   StockSign,a.fmkunitid   as   funitid,b.fitemid   as   fitemid,1   as   fqty
    into   #Tmp02   from   Ks_Tenancy   a
    inner   join   Ks_TenancyEntry   b   on   b.finterid=a.finterid   and   (b.FutSign=0)
    inner   join   ks_item   c   on   c.fitemid=b.fitemid
    inner   join   ks_facetcodeentry   d   on   d.finterid=c.finterid   and   d.fentryid=c.fentryid   and   c.faentryid=0
    where   b.FTenancySDate <=@DyDate
        and   d.fkindid=@DvKindID
        and   a.FStatus=1
        and   not   d.FStatuID   in(0,1000)
        and   substring(d.facsstr,1,1)= '1 '
        and   a.fmkunitid   in(select   fitemid   from   ks_item   where   fitemclassid=3   and   fparentid=0)

  --所有外借的设备
  select   3   as   StockSign,a.FOutUnitID   as   funitid,b.fitemid   as   fitemid,1   as   fqty
    into   #Tmp04   from   Ks_OuterBorrow   a
    inner   join   Ks_OuterBorrowEntry   b   on   b.finterid=a.finterid   and   (b.fsign=0)
    inner   join   ks_item   c   on   c.fitemid=b.fitemid
    inner   join   ks_facetcodeentry   d   on   d.finterid=c.finterid   and   d.fentryid=c.fentryid   and   c.faentryid=0
    where   a.fdate <=@DyDate
      and   d.fkindid=@DvKindID
      and   a.FStatus=1
      and   not   d.F