A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Cannot post code on this thread.
,(row_number() Over(partition by ID order by newid())-1)%4 +1 grp
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Using the CTE code below; how do I also display a running counter like the following with the rest of the data? So the first pair of 4 records will have 1, 2, 3, 4 and the next pair of 4 records will have 1, 2, 3, 4 and so on.
MyCounter ID CustNum CustAddr CustCity xxxxxxxxxxxxxxxx
1
2
3
4
1
2
3
4
1
2
3
4
;with cte as
(
select ID, CustNum, CustAddr, CustCity, CustState, CustZip, CustPhone,OrderNumber
from #test
)
SELECT ID, CustNum, CustAddr, CustCity, CustState, CustZip, CustPhone
, c AS OrderNumber into #test2 from cte
CROSS APPLY (SELECT value FROM STRING_SPLIT(OrderNumber, '|')) AS t(c)
select *from #test2
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Answer accepted by question author
Cannot post code on this thread.
,(row_number() Over(partition by ID order by newid())-1)%4 +1 grp
DDL
create table #test
(
ID INT,
CustNum INT,
CustAddr VARCHAR(30),
CustCity VARCHAR(30),
CustState CHAR(2),
CustZip CHAR(5),
CustPhone VARCHAR(20),
OrderNumber VARCHAR(MAX)
)
insert into #test values
(1, 1234, '55 Sunset Blvd', 'Hollywood', 'CA', '90045' ,'213-555-1212', '11111|22222|33333|444444');