MS Sql server 2000:
例:表ATable.Content字段为>8000字节的Text类型字段,内容为文本,有换行。
请教高手:如何使用SQL 语句取出一行文本到@Str变量?

解决方案 »

  1.   

    DECLARE  @Str  varchar(10000)
    select  @Str=sdf  from TABLE1
    print @Str
      

  2.   

    varchar 是有最长8000字符的限制的。而ATable.Content字段内容是决对长于8000字节的。
    所以楼上两位非正解
      

  3.   

    DECLARE @text_value binary(16)
    SELECT @text_value = TEXTPTR(C_text) 
       FROM MyTable1 WHERE MyId=25
      

  4.   

    示例
    下例读取 pub_info 表中 pr_info 列的第 2 个至第 26 个字符。USE pubs
    GO
    DECLARE @ptrval varbinary(16)
    SELECT @ptrval = TEXTPTR(pr_info) 
       FROM pub_info pr INNER JOIN publishers p
          ON pr.pub_id = p.pub_id 
          AND p.pub_name = 'New Moon Books'
    READTEXT pub_info.pr_info @ptrval 1 25
    GO
      

  5.   

    if exists(select name from sysobjects where name='t1' and type='u')
    drop table t1
    go
    create table t1(c1 int,c2 text)
    insert t1 values(1,'This is a text.')
    go
    declare @Str varbinary(16)
    select @Str=textptr(c2) from t1
    where c1=1
    readtext t1.c2 @Str 0 15
    go