Get table name from column name........

  • Hi,

    Can you tell me how can i get table(s) name from one column name that give me to put in a query?

    The point is:

    - They give me the following column name (OfferExternalID) and i need to join this query in one query but i don't know how can i get table name associated with this column. :blush:

    One other question, how can i send the output of one date in the following format (DD/MM/YYYY)? :sick:

    Thanks and regards

    JMSM

  • JMSM (2/8/2008)


    Hi,

    Can you tell me how can i get table(s) name from one column name that give me to put in a query?

    The point is:

    - They give me the following column name (OfferExternalID) and i need to join this query in one query but i don't know how can i get table name associated with this column. :blush:

    One other question, how can i send the output of one date in the following format (DD/MM/YYYY)? :sick:

    Thanks and regards

    JMSM

    The answer to your first question is that you can look at the sys.columns and sys.objects system views (I assume you are on SQL Server 2005)

    So in your case just see the result of the query:

    SELECT sch.name AS ParentSchema

    , so.name AS ParentName

    FROM sys.columns AS sc

    JOIN sys.objects AS so ON sc.object_id = so.object_id

    JOIN sys.schemas AS sch ON sch.schema_id = so.schema_id

    WHERE sc.name = 'OfferExternalID'

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Hi

    select object_name(object_id),* from sys.columns where

    name = 'OfferExternalID' -- put the column here.

    you can use the Convert function for formatting the date.

    "Keep Trying"

  • JMSM (2/8/2008)


    Hi,

    ...

    One other question, how can i send the output of one date in the following format (DD/MM/YYYY)? :sick:

    Thanks and regards

    JMSM

    Concerning your second question, you can use the style parameter of the convert function:

    select convert( varchar, getdate(),103)

    Will return:

    08/02/2008

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply