34,593
社区成员
发帖
与我相关
我的任务
分享
declare @t int
set @t=23
select 's'+right ('00000'+cast(@t as CHAR(3)),4)
这样更简单update B set 列2='s'+case when len(cast(列2 as CHAR(3)))=1 then '00'+cast(列2 as CHAR(3))
when len(cast(列2 as CHAR(3)))=2 then '0'+cast(列2 as CHAR(3)) else cast(列2 as CHAR(3)) end from A
你的意思是这样吗?根据b表列1,列2要改成 S007 这样的样式,s后面的数字跟着列一走?
with tb_A(列1)
as(
select 's001' union all
select 's002' union all
select 's003' union all
select 's004'),
tb_B(列1,列2, 列3)
as(
select 1, null, 23.5 union all
select 2, null, 43.5 union all
select 3 , null , 53.5 union all
select 4 , null , 63.5
)
select t2.列1,t1.列1,t2.列3 from (select row=ROW_NUMBER()over(order by getdate()),* from tb_A)t1,(select row=ROW_NUMBER()over(order by getdate()),* from tb_B)t2 where t1.row=t2.row