SUPERCAT.DEV

Benvenut* sul mio blog

TSQL

Permutazioni in SQL

28-03-2024

PiĆ¹ facile che in altri ambienti

DECLARE @T1 TABLE (COL1 CHAR(1))
DECLARE @T2 TABLE (COL2 CHAR(1))

INSERT INTO @T1 VALUES('A')
INSERT INTO @T1 VALUES('B')
INSERT INTO @T1 VALUES('C')

INSERT INTO @T2 VALUES('X')
INSERT INTO @T2 VALUES('Y')
INSERT INTO @T2 VALUES('Z')

SELECT COL1, COL2, COL1+COL2 PERMUTA FROM @T1, @T2

Risultato

COL1 COL2 PERMUTA
---- ---- -------
A    X    AX
B    X    BX
C    X    CX
A    Y    AY
B    Y    BY
C    Y    CY
A    Z    AZ
B    Z    BZ
C    Z    CZ