Link to home
Start Free TrialLog in
Avatar of Sandiya
Sandiya

asked on

Urgent: Get the missing column name

Hi,

I've a table namesly "course" in database1 "db1" & another table "course" in database2 "db2". I want to compare two tables & check whether two table columns are equal. If not equal, I have to find out the extra column or missing column and datatype and add the extra/missing column at runtime using alter table command.

How to get data type & column name...
Avatar of AncientAnt
AncientAnt

Are the fields unique in there respective columns?
Try this:

Edit
Sounds like you need a full outer join, in a function that returns a table wherethe full outer join finds nulls.  Maybe one for each table.  Then that could be the input for a transaction, or another stored procedure to uptadte the tables as needed.
hi

i recommend the following

dim dt1 as new datattable=get data from course in db1
dim dt2 as new datattable=get data from course in db2

then write a for loop to compare the columns name
ex: for i as integer=0 to dt1. Columns.Count -1 ...
and then u can know what is the missing
and base on that create a sql statement to do the necessary modification and execute it
Avatar of Sandiya

ASKER

The problem is that i cannot do a sql query because only the target datatable is from sql and the source datatable is from salesforce.Iam doing an import of data from salesforce and export it to sqlserver.

I have done coding to import the data from salesforce and export it to sqlserver.But say if they have added a custom field in the salesforce  and so i have to a comparison between datatables and find the missing column and then add that column to the sql server table.

i need a logic to compare two datatables for column names and then check whether there are any columns missing and then add that column to the target table in sql server.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sandiya

ASKER

Thanks Codecruiser the code worked like a charm.I am able to identify the missing column and will proceed to do the coding for alter table.