| |

VerySource

 Forgot password?
 Register
Search
Author: kittast

Find a SQL statement

[Copy link]

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-6-21 19:00:02
| Show all posts
to:sting0626()
The following paragraph is to generate an incremental temporary table of 1-8000, through the temporary table to take the value of the column,
The second method above the same couple is the same charindex(',',a.name+',',b.id)
The b.id of this paragraph is the position where the value of',' is found from the first few digits.
SELECT TOP 8000 id = identity(int,1,1)
INTO # FROM syscolumns a, syscolumns b
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 00:30:01
| Show all posts
select top 1000 id=identity(int,1,1) into #t from sysobjects,syscolumns

create table tableA(id int,gid varchar(8000))
insert tableA select 3456, '601988,600028,HK3988,HK0386'
insert tableA select 3457, '601988,600028'

go

select b.id,gid=substring(','+b.gid+',',a.id+1,charindex(',',','+b.gid+',',a.id+1)- a.id-1)
from #t a,tableA b
where substring(','+b.gid+',',a.id,1)=',' and len(b.gid)>a.id
order by a.id


drop table tablea,#T

/*result
id gid
---------------
3456 601988
3457 601988
3457 600028
3456 600028
3456 HK3988
3456 HK0386

*/
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 06:30:01
| Show all posts
Build a temporary table #t used as a cross-connect table tableA and locate the position of ","
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-29 11:30:01
| Show all posts
Learn! ~!
But my brother thought of another question!
Can it be the other way around?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list