declare @strsql char(500)
select @strsql='create table #temp'
select @strsql=rtrim(@strsql)+'(bookid,name)'

解决方案 »

  1.   

    declare @strsql char(500)
    declare @tmpsql char(500)
    select @strsql = 'create table #temp'
    select @tmpsql = '(bookid,name)'
    select @strsql=rtrim(@strsql) + @tmpsql
    print @tmpsql
    print @strsql
    由于你定义的字符串长度为500,不足500的自动加空格,所以@strsql加了'(bookid,name)'
    后中间有许多空格,而超过500个字符自动删除500以后的字符
      

  2.   

    declare @strsql varchar(500)  --改用varchar
    select @strsql='create table #temp'
    select @strsql=@strsql+'(bookid,name)'
      

  3.   

    declare @strsql varchar(500)
    select @strsql='create table #temp'
    select @strsql=@strsql+'(bookid,name)'
    select @strsql很简单吧,是不是和你的想法一样了?
      

  4.   

    方法一:
    declare @strsql char(500)
    select @strsql='create table #temp'
    select @strsql=rtrim(@strsql)+'(bookid,name)'
    方法二:
    declare @strsql varchar(500)
    select @strsql='create table #temp'
    select @strsql=@strsql+'(bookid,name)'
    select @strsql