ntext、text 和 image
用于存储大型非 Unicode 字符、Unicode 字符及二进制数据的固定长度和可变长度数据类型。Unicode 数据使用 UNICODE UCS-2 字符集。ntext可变长度 Unicode 数据的最大长度为 230 - 1 (1,073,741,823) 个字符。存储大小是所输入字符个数的两倍(以字节为单位)。ntext 在 SQL-92 中的同义词是 national text。text服务器代码页中的可变长度非 Unicode 数据的最大长度为 231-1 (2,147,483,647) 个字符。当服务器代码页使用双字节字符时,存储量仍是 2,147,483,647 字节。存储大小可能小于 2,147,483,647 字节(取决于字符串)。image可变长度二进制数据介于 0 与 231-1 (2,147,483,647) 字节之间。 注释
下面的函数和语句可以与 ntext、text 或 image 数据一起使用。函数 语句 
DATALENGTH  READTEXT 
PATINDEX SET TEXTSIZE 
SUBSTRING UPDATETEXT 
TEXTPTR WRITETEXT 
TEXTVALID   

解决方案 »

  1.   

    示例
    A. 使用 TEXTPTR
    下例使用 TEXTPTR 函数在 pubs 数据库的 pub_info 表中查找与 New Moon Books 相关联的 image 列 logo。文本指针放置在局部变量 @ptrval 中。 USE pubs
    GO
    DECLARE @ptrval varbinary(16)
    SELECT @ptrval = TEXTPTR(logo) 
    FROM pub_info pr, publishers p
    WHERE p.pub_id = pr.pub_id 
       AND p.pub_name = 'New Moon Books'
    GOB. 使用带行内文本的 TEXTPTR
    在 SQL Server 2000 中,行内文本指针必须在事务内部使用。示例如下:CREATE TABLE t1 (c1 int, c2 text)
    EXEC sp_tableoption 't1', 'text in row', 'on'
    INSERT t1 VALUES ('1', 'This is text.')
    GO
    BEGIN TRAN
       DECLARE @ptrval VARBINARY(16)
       SELECT @ptrval = TEXTPTR(c2)
       FROM t1
       WHERE c1 = 1
       READTEXT t1.c2 @ptrval 0 1
    COMMITC. 返回文本数据
    下例从 pub_info 表中选择 pub_id 列和 pr_info 列的 16 字节文本指针。USE pubs
    GO
    SELECT pub_id, TEXTPTR(pr_info)
    FROM pub_info
    ORDER BY pub_id
    GO下面是结果集:pub_id                                    
    ------ ---------------------------------- 
    0736   0x6c0000000000feffb801000001000100 
    0877   0x6d0000000000feffb801000001000300 
    1389   0x6e0000000000feffb801000001000500 
    1622   0x700000000000feffb801000001000900 
    1756   0x710000000000feffb801000001000b00 
    9901   0x720000000000feffb801000001000d00 
    9952   0x6f0000000000feffb801000001000700 
    9999   0x730000000000feffb801000001000f00 (8 row(s) affected)下例显示如何在不使用 TEXTPTR 的情况下返回文本的前 8,000 个字节。USE pubs
    GO
    SET TEXTSIZE 8000
    SELECT pub_id, pr_info
    FROM pub_info
    ORDER BY pub_id
    GO下面是结果集:pub_id pr_info                                                                                                                                                                                                                                                         
    ------ -----------------------------------------------------------------
    0736   New Moon Books (NMB) has just released another top ten publication. With the latest publication this makes NMB the hottest new publisher of the year!                                                                                                           
    0877   This is sample text data for Binnet & Hardley, publisher 0877 in the pubs database. Binnet & Hardley is located in Washington, D.C.This is sample text data for Binnet & Hardley, publisher 0877 in the pubs database. Binnet & Hardley is located in Washi 
    1389   This is sample text data for Algodata Infosystems, publisher 1389 in the pubs database. Algodata Infosystems is located in Berkeley, California.9999   This is sample text data for Lucerne Publishing, publisher 9999 in the pubs database. Lucerne publishing is located in Paris, France.This is sample text data for Lucerne Publishing, publisher 9999 in the pubs database. Lucerne publishing is located in (8 row(s) affected)D. 返回特定文本数据
    下例在 pubs 数据库的 pub_info 表中查找与 pub_id 0736 相关联的 text 列 (pr_info)。下例首先声明一个局部变量 @val。然后将文本指针(长二进制字符串)置于 @val 中,并将其作为参数提供给 READTEXT 语句,该语句将返回从第五个字节(偏移量为 4)开始的 10 个字节。USE pubs
    GO
    DECLARE @val varbinary(16)
    SELECT @val = TEXTPTR(pr_info) 
    FROM pub_info
    WHERE pub_id = '0736'
    READTEXT pub_info.pr_info @val 4 10
    GO下面是结果集:(1 row(s) affected)pr_info                                                                                                                                                                                                                                                         
    ------------------------------------------------------------------------
     is sample
      

  2.   

    示例
    本示例把文本指针置于局部变量 @ptrval 中,然后使用 UPDATETEXT 更新拼写错误。USE pubs
    GO
    EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
    GO
    DECLARE @ptrval binary(16)
    SELECT @ptrval = TEXTPTR(pr_info) 
       FROM pub_info pr, publishers p
          WHERE p.pub_id = pr.pub_id 
          AND p.pub_name = 'New Moon Books'
    UPDATETEXT pub_info.pr_info @ptrval 88 1 'b' 
    GO
    EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
    GO示例
    下例将文本指针放到局部变量 @ptrval 中,然后 WRITETEXT 将新的文本字符串放到 @ptrval 所指向的行中。USE pubs
    GO
    EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
    GO
    DECLARE @ptrval binary(16)
    SELECT @ptrval = TEXTPTR(pr_info) 
    FROM pub_info pr, publishers p
    WHERE p.pub_id = pr.pub_id 
       AND p.pub_name = 'New Moon Books'
    WRITETEXT pub_info.pr_info @ptrval 'New Moon Books (NMB) has just released another top ten publication. With the latest publication this makes NMB the hottest new publisher of the year!'
    GO
    EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
    GO
      

  3.   

    pls see:
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
      

  4.   

    --如果是存取文件/*--bcp 实现二进制文件的导入导出 支持image,text,ntext字段的导入/导出
    image适合于二进制文件,包括:Word文档,Excel文档,图片,音乐等
    text,ntext适合于文本数据文件 注意:导入时,将覆盖满足条件的所有行
    导出时,将把所有满足条件的行导出到指定文件中
    此存储过程仅用bcp实现
    邹建 2003.08-----------------*//*--调用示例
    --数据导出
    exec p_binaryIO 'zj','','','acc_演示数据..tb','img','c:\zj1.dat'--数据导入
    exec p_binaryIO 'zj','','','acc_演示数据..tb','img','c:\zj1.dat','',0
    --*/
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_binaryIO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[p_binaryIO]
    GOCreate proc p_binaryIO
    @servename varchar (30),--服务器名称
    @username varchar (30), --用户名
    @password varchar (30), --密码
    @tbname varchar (500),  --数据库..表名
    @fdname varchar (30),  --字段名
    @fname varchar (1000), --目录+文件名,处理过程中要使用/覆盖:@filename+_temp
    @tj varchar (1000)='',  --处理条件.对于数据导入,如果条件中包含@fdname,请指定表名前缀
    @isout bit=1 --1导出((默认),0导入
    AS 
    declare @fname_in varchar(1000) --bcp处理应答文件名
    ,@fsize varchar(20) --要处理的文件的大小
    ,@m_tbname varchar(50) --临时表名
    ,@sql varchar(8000)--则取得导入文件的大小
    if @isout=1 
    set @fsize='0'
    else
    begin
    create table #tb(可选名 varchar(20),大小 int
    ,创建日期 varchar(10),创建时间 varchar(20)
    ,上次写操作日期 varchar(10),上次写操作时间 varchar(20)
    ,上次访问日期 varchar(10),上次访问时间 varchar(20),特性 int)
    insert into #tb
    exec master..xp_getfiledetails @fname
    select @fsize=大小 from #tb
    drop table #tb
    if @fsize is null
    begin
    print '文件未找到'
    return
    endend--生成数据处理应答文件
    set @m_tbname='[##temp'+cast(newid() as varchar(40))+']'
    set @sql='select * into '+@m_tbname+' from(
    select null as 类型
    union all select 0 as 前缀
    union all select '+@fsize+' as 长度
    union all select null as 结束
    union all select null as 格式
    ) a'
    exec(@sql)
    select @fname_in=@fname+'_temp'
    ,@sql='bcp "'+@m_tbname+'" out "'+@fname_in
    +'" /S"'+@servename
    +case when isnull(@username,'')='' then '' 
    else '" /U"'+@username end
    +'" /P"'+isnull(@password,'')+'" /c'
    exec master..xp_cmdshell @sql
    --删除临时表
    set @sql='drop table '+@m_tbname
    exec(@sql)if @isout=1
    begin
    set @sql='bcp "select top 1 '+@fdname+' from ' 
    +@tbname+case isnull(@tj,'') when '' then ''
    else ' where '+@tj end
    +'" queryout "'+@fname
    +'" /S"'+@servename
    +case when isnull(@username,'')='' then '' 
    else '" /U"'+@username end
    +'" /P"'+isnull(@password,'')
    +'" /i"'+@fname_in+'"'
    exec master..xp_cmdshell @sql
    end
    else
    begin
    --为数据导入准备临时表
    set @sql='select top 0 '+@fdname+' into '
    +@m_tbname+' from ' +@tbname
    exec(@sql) --将数据导入到临时表
    set @sql='bcp "'+@m_tbname+'" in "'+@fname
    +'" /S"'+@servename
    +case when isnull(@username,'')='' then '' 
    else '" /U"'+@username end
    +'" /P"'+isnull(@password,'')
    +'" /i"'+@fname_in+'"'
    exec master..xp_cmdshell @sql

    --将数据导入到正式表中
    set @sql='update '+@tbname
    +' set '+@fdname+'=b.'+@fdname
    +' from '+@tbname+' a,'
    +@m_tbname+' b'
    +case isnull(@tj,'') when '' then ''
    else ' where '+@tj end
    exec(@sql) --删除数据处理临时表
    set @sql='drop table '+@m_tbname
    end--删除数据处理应答文件
    set @sql='del '+@fname_in
    exec master..xp_cmdshell @sqlgo
      

  5.   

    更多的参考我的贴子:数据库中存/取文件
    http://expert.csdn.net/Expert/topic/2403/2403509.xml?temp=.9905817