Skip to content
Advertisement

How to split one column with array merge value to array and join other table then merge back

There’s a table WaitCheckBil like :

and a table Users like :

Expected result :

What I’ve tried & think :

It’s a old system’s table , so I can’t change the struct.
And the table logic is select * from WaitCheckBil where usrs like '%;' + @usr + ';%'; to get user’s wait check bil_NO.

I think it could split ; usrs column value to array , then join with users table on user column, then merge back to users column.

But I have trouble on here , I have no idea how to implement the logic on sql-server 2008.

Online demo link : SQL Server 2017 | db<>fiddle

Advertisement

Answer

OK so here’s a UDF for SQL Server 2008:

Use it like so: SELECT [BIL_NO], dbo.ufnReplaceUIDs([USRS]) AS [USRS], [DATE] FROM WaitCheckBil and the result is:

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement