How can I get the number of columns in a given temporary table in the sql server ?
How can I get the number of columns in a given temporary table in the sql server ?
Hello, see if the code below meets your needs.
-- ==============================
-- exibindo qtd de colunas
-- ==============================
SELECT COUNT(*) AS QTD
FROM
sys.sysobjects AS T (NOLOCK)
INNER JOIN sys.all_columns AS C (NOLOCK) ON T.id = C.object_id AND T.XTYPE = 'U'
WHERE
T.NAME LIKE '%NOME_TABELA%'
-- ==============================
-- exibindo as colunas
-- ==============================
SELECT
T.name AS Tabela,
C.name AS Coluna
FROM
sys.sysobjects AS T (NOLOCK)
INNER JOIN sys.all_columns AS C (NOLOCK) ON T.id = C.object_id AND T.XTYPE = 'U'
WHERE
T.NAME LIKE '%NOME_TABELA%'
ORDER BY
C.column_id ASC