I would like to create a dynamic SQL update/insert statement based on some parsed data in a table in SQL and run this against an existing table in the same database. The issue I'm having is that some fields in the parsed datatable may not exist as fields in the copy-to table which will kill the statement. How can I check before hand?
i.e. parsed data table:
"address" "123 sample rd"
"customer" "bob's furniture"
Dynamic SQL along the lines of:
sql += "update tblCopyTo set "
for each row in parsed datatable
sql+= fieldname + "=" + value
so "phone" from dynamic SQL does not exist in tblCopyTo and the script will fail and not update any other parameters. Since the parsed data is not static, I need to be able to remove the non-existant fields before running the update script.
Can someone help me with the basic logic?