你想怎样过去?dts 
insert
update可以直接执行sql语句,不经过变量不行吗?

解决方案 »

  1.   

    楼主的要求用游标+ updatetext 即可实现updatetext的来源可以是text指针的, 如果你要经过处理, 可以先把数据放入临时表, 处理完成后再放入正式表
      

  2.   

    -- 这个示例和楼主的需求比较相似(游标+合并的处理)create table news(
    title1 nvarchar(10),content1 ntext,
    title2 nvarchar(10),content2 ntext,
    title3 nvarchar(10),content3 ntext,
    title4 nvarchar(10),content4 ntext)
    insert news select '1','aa','2','bb','3','cc','4','dd'
    union  all  select '11','aaa','22','bbb','33','ccc','44','ddd'
    union  all  select '111','aaaa','222','bbbb','333','cccc','444','dddd'
    create table article(id int identity,title nvarchar(20),content ntext)
    go--类似这样处理
    declare @p binary(16),@p1 binary(16),@p2 binary(16),@p3 binary(16),@p4 binary(16)
    ,@t nvarchar(4000)
    ,@t1 nvarchar(4000),@t2 nvarchar(4000),@t3 nvarchar(4000),@t4 nvarchar(4000)
    declare tb cursor local for
    select title1+'等'
    ,'<div align=center><font size=4>'+title1+'</div></font><br>&nbsp;&nbsp;'
    ,textptr(content1)
    ,'<div align=center><font size=4>'+title2+'</div></font><br>&nbsp;&nbsp;'
    ,textptr(content2)
    ,'<div align=center><font size=4>'+title3+'</div></font><br>&nbsp;&nbsp;'
    ,textptr(content3)
    ,'<div align=center><font size=4>'+title4+'</div></font><br>&nbsp;&nbsp;'
    ,textptr(content4)
    from news
    open tb
    fetch tb into @t,@t1,@p1,@t2,@p2,@t3,@p3,@t4,@p4
    while @@fetch_status=0
    begin
    insert article(title,content) values(@t,@t1)
    select @p=textptr(content) from article
    where id=@@identity  --如果 article 表没有自增字段,则不要这个条件(效果一样,但影响效率)
    updatetext article.content @p null 0 news.content1 @p1
    updatetext article.content @p null 0 @t2
    updatetext article.content @p null 0 news.content2 @p2
    updatetext article.content @p null 0 @t3
    updatetext article.content @p null 0 news.content3 @p3
    updatetext article.content @p null 0 @t4
    updatetext article.content @p null 0 news.content4 @p4
    fetch tb into @t,@t1,@p1,@t2,@p2,@t3,@p3,@t4,@p4
    end
    close tb
    deallocate tb
    goselect * from article
    godrop table article,news