Convert image datatype into varchar in sql server 2008

前端 未结 5 1895
后悔当初
后悔当初 2021-02-05 07:18

We have TestPartner database in SQL Server. The descriptions of the bugs are stored in \"image\" datatype column. We need to write a query to display the data as html table. We

5条回答
  •  礼貌的吻别
    2021-02-05 07:40

    My guess would be that the data stored in your image column is not 'normal' text - I would guess that it's some arbitrary data structure (hence the decision to use image rather than varchar) ?

    I tried this without a problem:

        declare @data varchar(max)
    
        declare @fred table (d1 varchar(max), d2 xml, d3 image)
    
        set @data = 'here is some data'
        while (len(@data) < 200)    set @data = @data + ' ' + cast(rand() as varchar)
    
        insert into @fred (d1,d2,d3) values (@data,@data,@data)
    
        set @data = 'here is some more data'
        while (len(@data) < 200)    set @data = @data + ' ' + cast(rand() as varchar)
    
        insert into @fred (d1,d2,d3) values (@data,@data,@data)
    
        declare @xml xml
        set @xml = (select cast(cast(d3 as varbinary(max)) as varchar(max)) as 'td' from @fred FOR XML PATH('tr'), TYPE)
    
        select @xml
    

提交回复
热议问题