DECLARE @str VARCHAR(100) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Biology Meta

Q&A about the site for biology researchers, academics, and students

DECLARE @str VARCHAR(100) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
DECLARE @num VARCHAR(100) = '0123456789';

;WITH E1(N) AS( -- 10 ^ 1 = 10 rows
    SELECT 1 FROM(VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1))t(N)
),
E2(N) AS(SELECT 1 FROM E1 a CROSS JOIN E1 b), -- 10 ^ 2 = 100 rows
E4(N) AS(SELECT 1 FROM E2 a CROSS JOIN E2 b), -- 10 ^ 4 = 10,000 rows
CteTally(N) AS(
    SELECT TOP(LEN(@str)) ROW_NUMBER() OVER(ORDER BY(SELECT NULL))
    FROM E4
)
SELECT  (
    SELECT TOP(2)
        SUBSTRING(@str, N, 1), SUBSTRING(@num, N, 1)
    FROM CteTally t
    ORDER BY NEWID()
    FOR XML PATH('')
) AS Result

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results