执行select显示某个字段的内容,怎样分行显示该内容?

liuzixi 2008-03-10 03:04:49
由于该字段是text类型,内容很长,结果在一行中看,很不方便
...全文
223 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leisure_cool 2008-03-11
  • 打赏
  • 举报
回复
学习
qqhmitzk 2008-03-10
  • 打赏
  • 举报
回复
改下2楼的
if   exists   (select   1   from   sysobjects   where   name='tb'   and   type='u')     
drop table tb
go
create table tb (id1 int , test varchar(8000))
insert into tb select 1,'abcdefghijklmnopqrstuvwxyz'
union select 2 ,'测试数据,测试数据测试数据测试数据'
union select 3 ,'可将函数和变量声明为 table 类型。table 变量可用于函数、存储过程和批处理中。'
go
if exists (select 1 from sysobjects where name='getrowtext' and type='p')
drop proc getrowtext
go
create proc getrowtext (@len int) as
begin
declare @pos int,
@i int,
@times int,
@id int,
@text varchar(255)
declare @tmptb table(id1 int, test varchar(255))
declare tb_cursor cursor for select id1, test from tb order by id1
open tb_cursor
fetch next from tb_cursor into @id, @text
while @@fetch_status = 0
begin
set @i=1
set @pos=1
set @times=len(@text)/@len+1
while @i <=@times
begin
insert into @tmptb select @id, substring(@text,@pos,@len)
set @pos=@pos+@len
set @i=@i+1
end
fetch next from tb_cursor into @id, @text
end
close tb_cursor
deallocate tb_cursor
select * from @tmptb
end

最好用程序控制,SQL不是万能的
qqhmitzk 2008-03-10
  • 打赏
  • 举报
回复
2楼用关键字做字段名,不妥把
能调试通过
areswang 2008-03-10
  • 打赏
  • 举报
回复
--测试表
if exists (select 1 from sysobjects where name='tb' and type='u')
drop table tb
create table tb (id int ,text varchar(8000))
insert into tb select 1,'abcdefghijklmnopqrstuvwxyz'
union select 2 ,'测试数据,测试数据测试数据测试数据'
union select 3 ,'可将函数和变量声明为 table 类型。table 变量可用于函数、存储过程和批处理中。'

--创建存储过程
if exists (select 1 from sysobjects where name='getrowtext' and type='p')
drop proc getrowtext
go
create proc getrowtext (@len int) as
begin
declare @pos int,
@i int,
@times int,
@id int,
@text varchar(255)
declare @tmptb table(id int, text varchar(255))
declare tb_cursor cursor for select id, text from tb order by id
open tb_cursor
fetch next from tb_cursor into @id, @text
while @@fetch_status = 0
begin
set @i=1
set @pos=1
set @times=len(@text)/@len+1
while @i<=@times
begin
insert into @tmptb select @id, substring(@text,@pos,@len)
set @pos=@pos+@len
set @i=@i+1
end
fetch next from tb_cursor into @id, @text
end
close tb_cursor
deallocate tb_cursor
select * from @tmptb
end

--测试数据
exec getrowtext 10
dawugui 2008-03-10
  • 打赏
  • 举报
回复
这不是SQL的功能吧?

自己在前台通过软件来做.

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧