Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Unanswered: How to determine data types from an SQL query?

    I am using SQL Server 2008 and the sqlcmd client. I would like to obtain the system data types (e.g., char, varchar, int, float, etc.) associated with each column returned by arbitrary queries. These "arbitrary queries" may include joins and otherwise dynamically generated columns.

    Thanks much,
    Jeff

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    No can do without submitting additional queries. Look at joining sys.columns and sys.types. You can determine the table the columns belong to by joining to sys.tables, or using OBJECT_NAME(columns.object_id).
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    ...and even then that won't cover all bases! What happens if you perform any casting/converting (implicitly or explicitly) within your query? What about constants? etc.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •