表中有一Image字段,存储的是一段文字
怎么样将这个字段内容以文字型式显示出来? 就是将以Image形式存储的内容在执行select语句时转换成nvarchar型显示

解决方案 »

  1.   


    create table #t(id int identity,v image)insert #t select '萨法萨队法'select id,convert(varchar(100),convert(binary(8000),v)) from #t
    /*
    id                                                                                                               
    ----------- ---------------------------------------------------------------------------------------------------- 
    1           萨法萨队法(所影响的行数为 1 行)*/
      

  2.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(ID int identity,test image)
    insert tb select '表中有一Image字段,存的是一段文字'
    select ID,
           cast(cast(test as varbinary(2000)) as varchar(1000))test 
    from tb
    /*
    ID          test
    ----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1           表中有一Image字段,存的是一段文字(1 個資料列受到影響)
    */
      

  3.   

    谢谢大家,我自己用convert就是转换不出来,原来要用cast才能正确转换
      

  4.   

    原来是要用varchar而不能用nvarchar