1

How to create a stored procedure (for SQL Server 2000 / 2005) to swap 2 records excluding a few columns, it has to get "table name", "record id (2 id)" and "column to exclude" as a parameter. Here columns are dynamic as we get 'table' as a parameter and number of columns may be more than 50.

Here I believe, "update [table name] set [field] = [value] ......"

Type statements will be very lengthy as the number of columns will be more than 50 and it is a variant.

Is there any simple way to swap records in SQL Server 2000/2005?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dhanapal
  • 14,239
  • 35
  • 115
  • 142
  • Do you really need to use dynamic SQL? I have looked at your other question http://stackoverflow.com/questions/464191/assign-function-result-to-a-table-variable and it it also trying to use dynamic SQL. Is there any special reasoning behind this? – kristof Jan 22 '09 at 12:11

1 Answers1

0

Check this answer by Tom H. to similar question.

Also this solution posted on SQLServerCentral may be helpful to you (the site requires registration but it is free)

Community
  • 1
  • 1
kristof
  • 52,923
  • 24
  • 87
  • 110