求SQL语句,菜鸟求答案

wsmhzyaba 2011-02-24 04:00:57
数据表A如下
id styleid lix
01 SHT009T 5

我要在临时表中显示如下内容
id styleid
01 SHT009T
02 SHT009T
03 SHT009T
04 SHT009T
05 SHT009T
语句怎么个写法?



...全文
54 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
AcHerat 元老 2011-02-24
  • 打赏
  • 举报
回复

create table tb(ar varchar(5),ak varchar(10),cn int)
insert into tb
select '11','SHT009T',5
go

select right(10000 + cast(a.ar as int)+ b.number,2),a.ak
from tb a,master..spt_values b
where b.type = 'p' and b.number < a.cn

drop table tb



ak
---- ----------
11 SHT009T
12 SHT009T
13 SHT009T
14 SHT009T
15 SHT009T

(5 行受影响)
AcHerat 元老 2011-02-24
  • 打赏
  • 举报
回复

create table tb(ar varchar(5),ak varchar(10),cn int)
insert into tb
select '01','SHT009T',5
go

select right(10000+b.number,2),a.ak
from tb a,master..spt_values b
where b.type = 'p' and b.number < a.cn

drop table tb


ak
---- ----------
00 SHT009T
01 SHT009T
02 SHT009T
03 SHT009T
04 SHT009T

(5 行受影响)
快溜 2011-02-24
  • 打赏
  • 举报
回复
 create table tb(id char(10),styleid char(20),lix int)
insert into tb
select '01','SHT009T',5

select '0'+rtrim(a.number+1) as id ,b.styleid
from master..spt_values a,tb b
where type='p' and a.number<b.lix

/*
id styleid
------------- --------------------
01 SHT009T
02 SHT009T
03 SHT009T
04 SHT009T
05 SHT009T
王向飞 2011-02-24
  • 打赏
  • 举报
回复
select b.id,b.styleid,'0'+ltrim(a.number+1)
from master..spt_values a,tb b
where type='P' and a.number<b.lix
快溜 2011-02-24
  • 打赏
  • 举报
回复
 create table tb(id char(10),styleid char(20),lix int)
insert into tb
select '01','SHT009T',5

select b.id,b.styleid
from master..spt_values a,tb b
where type='p' and a.number<b.lix

/*
id styleid
---------- --------------------
01 SHT009T
01 SHT009T
01 SHT009T
01 SHT009T
01 SHT009T

34,593

社区成员

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

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