如select * from table1,可以得到结果如下
name value
张三 2我现在想把这个结果变成
name value
张三 1
张三 1把value字段拆分成多条显示,每次都显示为1,SQLSERVER能不能实现如上答者有分
name value
张三 2我现在想把这个结果变成
name value
张三 1
张三 1把value字段拆分成多条显示,每次都显示为1,SQLSERVER能不能实现如上答者有分
解决方案 »
- 备份数据库服务器下的某个目录
- 数据库字段值有多种情况,我需要取特定字符之前的字符
- 内部排序怎样用网页显示
- 请问一下表A中漏填的内容用哪个语句可以等于表B的内容
- 求一个sql语句
- 超简单SQL语句.在线等,解决给分
- 哥哥们有兴趣帮忙看看这个视图怎么做!
- 如果对方电脑能PING通我的服务器的IP,并有数据库的用户名是否就可以访问我的服务器数据库了?
- sql server 2008 变量可以分割吗?
- 高手请进!!!高分相赠!!有关sqlserver吃内存的问题!!!
- 高手帮忙写一句查询SQL,查询结果不显示某列数据为空and为英文字母
- 为啥sqlsever2000的float 10/100 的结果不是0.1呢?
这个值是直接保存在表中的吗?
值是直接保存的
create table tb(name varchar(10),value int)
insert tb(name,value)
select '张三','2' union all
select '李四','3'
go
--执行测试语句
create table #tb(name varchar(10),value int)declare @name varchar(10),@value intdeclare t_cursor cursor for
select t.name,t.value from tb t
open t_cursor
fetch next from t_cursor into @name,@value
while @@fetch_status = 0
begin
while @value > 0
begin
insert #tb select @name,1
set @value = @value - 1
end
fetch next from t_cursor into @name,@value
end
close t_cursor
deallocate t_cursorselect * from #tb
go
--删除测试环境
drop table tb,#tb
go
/*--测试结果
name value
---------- -----------
张三 1
张三 1
李四 1
李四 1
李四 1(5 row(s) affected)
*/
create table #t(name varchar(20),value int) declare @i int
select @i=0 from tb
while ((select count(*) from tb where value-@i>=1)>0)
begin
insert into #t
select name as [name],'1' as value from tb where value-@i>0
select @i=@i+1
end
select * from #t
drop table #t
create table tb(name varchar(10),value int)
insert tb(name,value)
select '张三','2' union all
select '李四','3'/*--测试结果
name value
-------------------- -----------
张三 1
李四 1
张三 1
李四 1
李四 1
insert table1(name,value)
select '张三','2' union all
select '李四','3'
goset rowcount 10000
select identity(int,1,1) as id into # from sysobjects,syscolumns
set rowcount 0select a.name,1 as [value] from table1 a,# b where a.[value]>=b.id order by a.name
go/*
name value
---------- -----------
李四 1
李四 1
李四 1
张三 1
张三 1
*/drop table #,table1
go
set rowcount 10000
select identity(int,1,1) as id into # from sysobjects,syscolumns
set rowcount 0