Hi All,
I have an MS SQL database, I want to be able to create a new record based on a prevoius record, the SQL statement I have is this:
strSQL = "INSERT INTO tableX " & _
"SELECT * FROM tableX WHERE " & _
"id='1'"
The problem I have is that the primary Key (id) is set to Identity and so won't allow duplicates, I need this SQL to work but give the id value a new unique value.
Thanks All
Paul
If this doesn't need to be generic then add the field name list to both parts, but leave out the id field
Assume id is field0
Code:
INSERT INTO TableX(Field1, Field2, Field3)
SELECT Field1, Field2, Field3 FROM TableY WHERE id=1
Was this answer helpful ?
Yes No
Thanks for this, however I have about 200 fields in each record, and just want a generic copy paste solution if this can be done.
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by pts69 Thanks for this, however I have about 200 fields in each record, and just want a generic copy paste solution if this can be done. |
holy crap...i hope this was a typo!
Was this answer helpful ?
Yes No
Quote:
| Originally Posted by bslintx holy crap...i hope this was a typo! |
Rather a lot isn't it, I can't think of any pure sql way that is going to help, other than typing all the field names out.
Was this answer helpful ?
Yes No
Seriously, think about normalising your database first. Your going to run into alot of trouble at some point. Speed can be increased alot if you split up the fields.
There is no way that any database needs 200 fields.
Was this answer helpful ?
Yes No
200 fields <<<<<<<<<<<<<<< Mayur Faints
Was this answer helpful ?
Yes No