数据有900多条,其中一个字段hb_url内容有以下2种类型:第一集$45445454
第二集$7979898和
4545343545
4543545455
3545454545
4534543545也就是说相同点都是一行一条数据,不同点是一个带$一个不带现在我需要生成数据,以$做分隔,遇到下面不带$就报错,现求一sql查询,将不带$的数据都加上$,前面再添加相应的集数,如:第1集$4545343545
第2集$4543545455
第3集$3545454545
第4集$4534543545 能做到吗?
第二集$7979898和
4545343545
4543545455
3545454545
4534543545也就是说相同点都是一行一条数据,不同点是一个带$一个不带现在我需要生成数据,以$做分隔,遇到下面不带$就报错,现求一sql查询,将不带$的数据都加上$,前面再添加相应的集数,如:第1集$4545343545
第2集$4543545455
第3集$3545454545
第4集$4534543545 能做到吗?
select '$'+hb_url from 数据表 where hb_url not like '%$%'
if object_id('tempdb.dbo.#') is not null drop table #
create table #(Col varchar(15))
insert into #
select '第一集$45445454' union all
select '第二集$7979898' union all
select '4545343545' union all
select '4543545455' union all
select '3545454545' union all
select '4534543545'select Col = '第' + ltrim(row_number()over(order by getdate())) + '集$' + Col from # where Col not like '%$%'/*
Col
--------------------------------------------
第1集$4545343545
第2集$4543545455
第3集$3545454545
第4集$4534543545
*/
set 列= '第' + row_number() over(order by getdate()) + '集$' + 列
where 列 not like '%$%'
第1集$4545343545
第2集$4543545455
第3集$3545454545
第4集$4534543545
。
每一行后面的数据都不一样的,我只是举例。