June 24, 2014 at 6:29 pm
I have a script that loops through a series of tables to send data to a table from each of the tables. My issue is that not all tables have the columns I need in them. What I would like is to replace the column with another column when it does not exist. Something like below
Select Misisng_Column(A.Name, replace with B.Name) as Name
FROM SomeTable A
Cross Join (Select Name FROM AnotherTable) B
AnotherTable has one record in it. To avoid a Cartesian issue. Like I said just an example
In my real script the table aliased as A is from a list of tables in a sys.tables query that loops through to the end.
Any help would be greatly appreciated.
June 25, 2014 at 3:41 am
If you're using the sys tables (i.e. views) as source of the table names, use the columns view to identify the required column name & store this along with the table name.
Then use dynamic SQL to generate the SQL statement.
June 26, 2014 at 7:47 am
laurie-789651 (6/25/2014)
If you're using the sys tables (i.e. views) as source of the table names, use the columns view to identify the required column name & store this along with the table name.Then use dynamic SQL to generate the SQL statement.
+1
Cheers
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply