有这样一个表
col1    col2
------------
1       abc
2       def
3       ghi现在我想建一个视图,希望视图的类容如下
col1    col2
---------------
1       def_ghi
2       abc_ghi
3       abc_def这个如何实现呢?

解决方案 »

  1.   

    如果是4条的话
    视图如下
    1   def_ghi_jkl
    2   abc_ghi_jkl
    3   abc_def_jkl
    4   abc_def_ghi规则就是把表中 出去当前行的col2字段对应的所有字符连成一个长的字符串
      

  2.   

    try:
    declare @t table (col1 int identity(1,1),col2 varchar(3))
    insert into @t 
    select 'abc'
    union select 'dfg'
    union select 'hij'
    union select 'klm'--------------
    declare @str varchar(8000)
    set @str=''
    select @str=@str+col2+'_' from @t
    set @str=left(@str,len(@str)-1)select col1,replace(replace(replace(@str,col2,'*'),'*_',''),'_*','') col2 from @t