-3

I have table a ,table b with same columns .I want to replace the value in table b with table a value without using update keyword.

1 Answers1

1

The question could use a bit more detail on the table structure, what exactly you're trying to accomplish, and what precludes you from using UPDATE, but here goes:

CREATE TABLE #tempTable (col1, col2, col3, ...)

INSERT INTO #tempTable
SELECT 
 b.col1
 , b.col2
 , a.col3
 , ...
FROM a
INNER JOIN b
ON a.col1 = b.col1

DELETE FROM b
WHERE col1 IN (SELECT col1 FROM a)

INSERT INTO b
SELECT
 col1
 , col2
 , col3
 , ...
FROM #TempTable

Which of course makes the bold assumption that Table a and b share a primary key, and that Table b doesn't have any constraint that would prevent deletion of matched rows. Please, provide some more detail and I'll update my answer accordingly.

Vocoder
  • 144
  • 5