WITH BASE as(
SELECT CONCAT (TABLE_SCHEMA, '.', TABLE_NAME)as TABLE_NAME
, COLUMN_NAME
, DATA_TYPE
, CHARACTER_MAXIMUM_LENGTH
, CHARACTER_OCTET_LENGTH
, NUMERIC_PRECISION
, NUMERIC_PRECISION_RADIX
, DATETIME_PRECISION
, IIF(IS_NULLABLE = 'YES', ',', 'NotNull') AS NN
, ORDINAL_POSITION
FROM [INFORMATION_SCHEMA].[COLUMNS]
WHERE TABLE_NAME IN ('{ テーブル物理名 }')
)
SELECT TABLE_NAME AS 'テーブル名'
, COLUMN_NAME AS 'カラム名'
, DATA_TYPE AS '型'
, CASE
WHEN DATA_TYPE in ('char', 'nchar', 'nvarchar', 'varchar') THEN
IIF(CHARACTER_MAXIMUM_LENGTH > 0, CHARACTER_MAXIMUM_LENGTH, '')
WHEN DATA_TYPE in ('bigint', 'int', 'tinyint') THEN
IIF(NUMERIC_PRECISION > 0, NUMERIC_PRECISION, '')
WHEN DATA_TYPE in ('numeric', 'decimal') THEN
IIF(NUMERIC_PRECISION > 0, NUMERIC_PRECISION, '')
--IIF(NUMERIC_PRECISION > 0, CONCAT(NUMERIC_PRECISION, NUMERIC_SCALE) , '')
WHEN DATA_TYPE in ('bit', 'varbinary', 'date', 'datetime') THEN ''
ELSE ''
END AS 桁
, NN AS NotNull
FROM BASE
ORDER BY TABLE_NAME, ORDINAL_POSITION
;