create proc pro_updateSimple
@content text,
@cshort char(4),
@kind varchar(20)
as
declare @sql text
select @sql='update tbUp188_SimpleSet set '+@kind+'='''+@content+''' where SSCShort='''+@cshort+''''
exec(@sql)
go
本来是:exec('update tbUp188_SimpleSet set '+@kind+'='''+@content+''' where SSCShort='''+@cshort+'''')没错。但是想换成上面那种写法,但是出错了:对于局部变量,text、ntext 和 image 数据类型无效。求解。谢谢。搞定立马结贴。。

解决方案 »

  1.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+@content+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  2.   

    sql 2005以上的版本还可以用varchar(max)
      

  3.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql text
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar)+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  4.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+@content+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  5.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql as varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar)+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  6.   

    create proc pro_updateSimple
    @content varchar(max),
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(max)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+@content+''' where SSCShort='''+@cshort+''''
    print(@sql)
    go
      

  7.   

    ---或者
    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql text
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar(8000))+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  8.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar(8000))+''' where SSCShort='''+@cshort+''''
    exec(@sql)
      

  9.   


    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar(8000))+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  10.   

    create proc pro_updateSimple
    @content text,
    @cshort char(4),
    @kind varchar(20)
    as
    declare @sql varchar(8000)
    select @sql='update tbUp188_SimpleSet set '+@kind+'='''+cast(@content as varchar(8000))+''' where SSCShort='''+@cshort+''''
    exec(@sql)
    go
      

  11.   

    不过想说一句,参数用text类型是在是太糟糕了