AS400

SQL tips and tricks 1

SQL tips and tricks 1

Come controllare se una colonna carattere contiene valori numerici WITH T_01 (C02, C05, c07) AS (VALUES (’12’,’12345′, ‘1234567’), (‘1x’,’12M45′, ‘1234567’), (’12’,’12345′, ’12K4567′), (‘1a’,’12X45′, ‘123N567’), (‘1d’,’1c345′, ‘123d567’)) SELECT C02, (CASE WHEN (TRANSLATE(trim(C02), ‘NNNNNNNNNNX’, ‘1234567890N’)=’NN’) THEN ‘is numeric’ ELSE ‘not numeric’ END)…

Snippet Sql 2

Come ottenere lista colonne primary_key e constraint di una tabella ELECT A.TABLE_SCHEMA “SCHEMA”, A.TABLE_NAME, A.CONSTRAINT_TYPE “TYPE”, C.ORDINAL_POSITION “POS”, A.CONSTRAINT_NAME, C.COLUMN_NAME FROM QSYS2.SYSCST A LEFT OUTER JOIN QSYS2.SYSREFCST B ON A.CONSTRAINT_SCHEMA = B.CONSTRAINT_SCHEMA AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME LEFT OUTER JOIN QSYS2.SYSKEYCST…