Results 1 to 4 of 4

Thread: Information in a table

  1. #1
    Join Date
    Dec 2004
    Location
    Westlake, OH
    Posts
    4

    Question Information in a table

    I have a pretty complex question (at least I think it is) I have two tables that are structured like so
    TABLE 1: TABLE 2:
    HIGH ZIP ORIGIN
    TERMINAL 50 COLUMNS THAT
    CORRESPOND TO ABBREV
    OF THE TERMINALS IN T1

    I have a sproc that ends up with a time to get from one terminal to the other which is the information in t2. The sproc uses other tables that are not structured like these. What I want to do is take the column terminal in T1 and take the column value from the corresponding column in T2. If you need clarification let me know. I am trying to come up with the time it takes to get from termA to termB. I hope this gives you something to go on. In table2 the labels for each column also correspond to a terminal abbreviation. The values in the columns then give the time in days that it takes to get from the A to B and that is what I want to pull out.
    Anyhow I need a lot of help with this one
    Thank you in advance
    Max

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048

    Re: Information in a table

    Let's see if I understand correctly.

    In T1, the Terminal field will have values of TermA and TermB. In T2, the Origin column has the same values as the Terminal field in T1? And then T2 has 50 columns named to match the values in the Terminal field in T1, including TermA and TermB?

    So, if you want to know the time between TermA and TermB, you would do something like this:

    Select TermB
    From T2
    Where Origin = 'TermA'

    But you need to be able to do it dynamically. Like this:

    Declare @OriginTerm varchar(20),
    @EndTerm varchar(20),
    @SQL varchar(1000)

    Set @OriginTerm = 'TermA'
    Set @EndTerm = 'TermB'

    Set @SQL = 'Select [' + @EndTerm + '] From T2 Where Origin = ''' + @OriginTerm + ''''

    Exec (@SQL)



    Note: Those are all single quotes above, no double quotes.

  3. #3
    Join Date
    Dec 2004
    Location
    Westlake, OH
    Posts
    4
    Isn't the table structure on this really screwy! I thought I would have to do it dynamically after searching further. I really appreciate your time.

  4. #4
    Join Date
    Feb 2003
    Posts
    1,048
    Yes, it is screwy. This means if they open a new terminal, you have to add a column to Table 2. Screwy indeed.

Posting Permissions

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