Not sure quite how to even approach this question so feel free to get clarification if I thoroughly confuse...>God knows I AM!
Ok...
I have a procedure that pulls three columns from any given table. (Variable @TableName) But some of the tables do NOT have the same column name. Example...some tables have Code, Description, Name...OTHER tables have Abbreviation, Description and Name, and still OTHERS have Abbreviation & Description but no Name column. You can only imagine the other possibilities. but you get the idea...
So I've figured out how to make those work with dynamic SQL and temp tables...works like a charm! BUT, now I've been asked to add one more field, that again is not in every table. But if it doesn't exist, just show a default value. *sigh*
Is there a way to join to a "key field" if you do not know the name ahead of time? And if not is there a way to get the column name based on the ordinal_position? And can you get it from a temp table? (Global or local?)
If you understand any of this and can help, please respond...thank you in advance for any help you guys can provide.
Thanks,
RSBLaird
Ok...
I have a procedure that pulls three columns from any given table. (Variable @TableName) But some of the tables do NOT have the same column name. Example...some tables have Code, Description, Name...OTHER tables have Abbreviation, Description and Name, and still OTHERS have Abbreviation & Description but no Name column. You can only imagine the other possibilities. but you get the idea...
So I've figured out how to make those work with dynamic SQL and temp tables...works like a charm! BUT, now I've been asked to add one more field, that again is not in every table. But if it doesn't exist, just show a default value. *sigh*
Is there a way to join to a "key field" if you do not know the name ahead of time? And if not is there a way to get the column name based on the ordinal_position? And can you get it from a temp table? (Global or local?)
If you understand any of this and can help, please respond...thank you in advance for any help you guys can provide.
Thanks,
RSBLaird