Question

I have a table with a dozen or so columns. I only know the name of the first column and the last 4 columns (in theory, I could only know the name of one column and not its position)

How can I can I write a statement which ignores this column? At the moment I do various column counts in ASP and construct a statement that way but was wondering if there was an easier way

UPDATE

INSERT INTO tblName VALUES ("Value for col2", "Value for col3") 

but the table has a col4 and potentially more, which I'd be ignoring.

I basically have a CSV file. This CSV file has no headers. It has 'X' less columns than the table I'm inserting into. I would like to insert the data from the CSV into the table.

There are many tables of different structures and many CSV files. I have created a ASP page to take any CSV and upload it to the corresponding table (based on a parameter within the CSV file).

It works fine, I was just wondering that when I was doing the INSERT statement, if I could ignore certain columns and cut down on my code.

So let's say the CSV has data as follows

123 | 456 | 789
234 | 567 | 873

The table has a structure of

ID | Col1 | Col2 | Col3 | Col4 | Col5

I currently construct an insert statement that says

INSERT into tblName ("123", "456","789","","")

However I was wondering if there was a way I could omit the empty values by somehow "ignoring" the columns. As mentioned, the column names are not known apart from the ones I have no data for.

No correct solution

OTHER TIPS

There is no Sql shortcut for

Select * (except column col1) from ...

You have to construct your Sql from database metadata, like you already did if I understood you correctly.

You can specify the columns that you want to insert.

So instead of...

INSERT INTO tblName VALUES ("Value for col2", "Value for col3")

You could specify column names...

INSERT INTO tblName (ColumnName1, ColumnName2) VALUES ("Value for col2", "Value for col3")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top