Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Column Alias

  1. #1
    Join Date
    Jan 2004
    Posts
    164

    Unanswered: Column Alias

    Hello everyone.

    I was wondering if there is a way that you can set the alias name of a column to a value that resides in another table instead of the alias being a static value that you type in.

    If anyone has any ideas on ho i can accomplish this i would greatly appreciate it.

  2. #2
    Join Date
    Aug 2006
    Location
    San Francisco, CA
    Posts
    136
    I don't know if you would be able to do it but I have 2 ideas that might work.

    1. do some kind of sub query which would return the alias name

    2. write a stored procedure in which you could write a query to get the alias name, assign that to a variable, and then use the variable as the alias in the next query.

    I have no idea if either one of these will work, but they are just some ideas.
    I hope this helped
    Good luck

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You can do this with dynamic SQL.

    As a matter of fact, you can do also sorts of stupid things with dynamic SQL. And many people take up the challenge.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Jan 2004
    Posts
    164
    Thanks for the suggestions. I am doing a little research to see how i can accomplish this using dynamix sql statements.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    And the challenge has been accepted.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Is there a problem with aliasing the column in a view?

  7. #7
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by blindman
    And the challenge has been accepted.
    Oh great. Are you gonna pay for my new keyboard (after I just spit my coke all over it)?

    Regards,

    hmscott
    Have you hugged your backup today?

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    First of all, if you just sniffed the coke, how on earth did you end up spitting it onto your keyboard? Its not really any of my business I guess, but inquiring minds want to know.

    More importantly, I saw this one coming a long way off, and I'm usually the optimist in this crowd... Why should Blindman buy you new coke when you ought to have expected this quite a while back?

    -PatP

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Coke? Keyboard? hmscott?

    OK, I'm lost now.

    The poster is (against advice) taking the "dynamic sql challenge". You appear to be confusing this with the "Pepsi Challenge".
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  10. #10
    Join Date
    Aug 2006
    Location
    San Francisco, CA
    Posts
    136
    Just to clarify, I do not support dynamic sql statements, but it seemed like the only way to achieve the goal. If anybody has a better idea I am all ears.

  11. #11
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    To paraphrase Slim Pickens from BLAZING SADDLES ...Why in the wide, wide world of sports would you want to do that?

    -- This is all just a Figment of my Imagination --

  12. #12
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    In this case, it would be more appropriate to paraphrase Slim Pickens whooping and hollering as he rides the nuclear warhead down to destruction in "Dr. Strangelove".
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  13. #13
    Join Date
    Jan 2004
    Posts
    164
    well i know you can also update the column name in the syscolumn table.

    I would have to use:

    sp_configure 'allow updates', 1
    GO
    RECONFIGURE WITH OVERRIDE
    GO

    This will allow me to use ad hoc commands to rename table. But i am not sure if allowing updates on the system tables would be an approach to take.

  14. #14
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Modifying system tables beats dynamic SQL every time when you are looking to create self-inflicted injuries!

    -PatP

  15. #15
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    But of course, modifying system tables WITH dynamic sql would be like the biathalon of bad design!
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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