locked
Data type returned by sql select query RRS feed

  • Question

  • is there a way to get the data type being returned?

    ie select myfield.type from table

    thanks

    David
    Monday, September 28, 2009 7:42 AM

Answers

  • You can't get this info direct from the query, but INFORMATION_SCHEMA should help:

    SELECT DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'MyTable'
    	AND COLUMN_NAME = 'MyColumn'
    


    every day is a school day
    • Marked as answer by Zongqing Li Friday, October 2, 2009 2:27 AM
    Monday, September 28, 2009 10:36 AM

All replies

  • You can use sys.columns and sys.types to get such information.
    Monday, September 28, 2009 8:51 AM
  • try this

    select c.name 'column name', t.name 'type' from sys.columns c
    	inner join sys.types t on t.system_type_id = c.system_type_id
    where object_name(object_id) = 'Mytable'
    Monday, September 28, 2009 9:01 AM
  • You can't get this info direct from the query, but INFORMATION_SCHEMA should help:

    SELECT DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'MyTable'
    	AND COLUMN_NAME = 'MyColumn'
    


    every day is a school day
    • Marked as answer by Zongqing Li Friday, October 2, 2009 2:27 AM
    Monday, September 28, 2009 10:36 AM