db fixes and coding errors

a couple of coding errors fixed, made a change to the if/else statement
so that it can pull back all the tables or views if none are defined.

functions : check_table_exists was closing the cursor so removed those
lines

added commas to sqlserver_datatypes that were missing