Select column type that comes in a SELECT

Asked

Viewed 728 times

2

Hello, my question is this::

I have a Select in Sqlserver of two tables with Inner Join, they return me a set of 5 columns. I would like to know how to list the type of these columns.

I know you have a way of showing the speaker type with SP_Columns, but it only shows me if the parameter passed is a table or view.

My select is this:

SELECT *
FROM Produtos p
INNER JOIN Marca m
ON p.prodcodigo=m.prodcodigo
  • 1

    When you do a query or cursor to retrieve values in SQL Server, you need to define the types of variables that will receive these values. In pure T-SQL I do not think it is possible to do this unless, perhaps, with an immense gambiarra of dynamic queries generation. On the other hand, if you are accessing the database with a programming language it would be possible to access the query meta-data.

1 answer

1


You can use the metadata table SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS, but you won’t be able to relate to your table. There are two alternatives to this.

In the first, it will be necessary to make multiple queries, until you get the desired result. In the second, a column is created in your bank, keeping the data type, as value.

  • 1

    I made a view with the query, then used Sp_columns to see the result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.