---------------------------------------------------------------- -- Author :fredrickhu(小F,向高手学习) -- Date :2011-09-07 15:10:31 -- Verstion: -- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) -- Apr 22 2011 11:57:00 -- Copyright (c) Microsoft Corporation -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64) -- ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([col] image) insert [tb] select 'aa' --------------开始查询--------------------------select cast(CAST (col as varbinary) as varchar(10)) from [tb] ----------------结果---------------------------- /* ---------- aa(1 行受影响)*/
选转换成varbinary 再转换成varchar
create table tb(col image) insert into tb select 'abcd张三dwrd' go select convert(varchar,convert(varbinary,col)) from tb /* ------------------------------ abcd张三dwrd(1 行受影响)*/ go drop table tb
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-09-07 15:10:31
-- Verstion:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
-- Apr 22 2011 11:57:00
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col] image)
insert [tb]
select 'aa'
--------------开始查询--------------------------select cast(CAST (col as varbinary) as varchar(10)) from [tb]
----------------结果----------------------------
/* ----------
aa(1 行受影响)*/
insert into tb select 'abcd张三dwrd'
go
select convert(varchar,convert(varbinary,col)) from tb
/*
------------------------------
abcd张三dwrd(1 行受影响)*/
go
drop table tb
还是有乱码。
附上image字段的数据:0x3C68746D6C3E3C626F64793EE68993E58F91E5A3ABE5A4A7E5A4AB3C2F626F64793E3C2F68746D6C3E
参考:
图像文件的读取
http://blog.csdn.net/htl258/archive/2010/04/15/5486178.aspx