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.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|||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.|||Thanks for the suggestions. I am doing a little research to see how i can accomplish this using dynamix sql statements.|||And the challenge has been accepted.|||Is there a problem with aliasing the column in a view?|||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|||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|||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".|||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.|||To paraphrase Slim Pickens from BLAZING SADDLES ...Why in the wide, wide world of sports would you want to do that?|||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".|||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.|||Modifying system tables beats dynamic SQL every time when you are looking to create self-inflicted injuries!
-PatP|||But of course, modifying system tables WITH dynamic sql would be like the biathalon of bad design!|||trifecta if you do it in a stored proc with a cursor|||trifecta if you do it in a stored proc with a cursorOh ouch!
-PatP|||there is a much easier way of doing this if the alias names are again column names of some other table and the datatype matches. is that the case?|||Assume it is. You've piqued my curiosity. What are you proposing?|||Ummm...Is there a problem with aliasing the column in a view?|||Assume it is. You've piqued my curiosity. What are you proposing?
select top 0 * from TableHavingAliasColName
union
select * from TableWithDiffColName
OR
select top 0 * into Dummy from TableHavingAliasColName
insert into Dummy select * from TableWithDiffColName|||Ah. So the table schemas have to be identical.
But the poster wants to set the column name to the VALUE in another table. Not the column name from another table.
Very creative, though.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment