glenninflorida
Programmer
Hi all:
I'm in need of the best practice for the following:
I need to update the destination table with only new records from a source table. I can use the following to append "new / non-existant" records.
INSERT INTO destination
SELECT user, status
FROM source
WHERE NOT EXISTS
(SELECT *
FROM destination
WHERE ISNULL(destination.user,'XX') = ISNULL(source.user,'XX'))
However..., I need to manipulate the data along the way since and one of the fields (status) has a different data type and value.
source.status type = text , values are "A" and "I"
destination.status type = bit , values are 0 and 1 (stating the obvious here
I'm thinking I will need to use a cursor since each row must be tested and manipulated.
or I could create an extra column in destination table and create an sproc that:
1) does the insert statment above
2) does an update statement from extra column to status
I think (based on very little MS-SQL experience) the cursor in an sproc would be cleaner, I've googled various cursor examples but have not found a similar example that I can use to learn from.
Your input is greatly appreciated.
Thanks
I'm in need of the best practice for the following:
I need to update the destination table with only new records from a source table. I can use the following to append "new / non-existant" records.
INSERT INTO destination
SELECT user, status
FROM source
WHERE NOT EXISTS
(SELECT *
FROM destination
WHERE ISNULL(destination.user,'XX') = ISNULL(source.user,'XX'))
However..., I need to manipulate the data along the way since and one of the fields (status) has a different data type and value.
source.status type = text , values are "A" and "I"
destination.status type = bit , values are 0 and 1 (stating the obvious here
I'm thinking I will need to use a cursor since each row must be tested and manipulated.
or I could create an extra column in destination table and create an sproc that:
1) does the insert statment above
2) does an update statement from extra column to status
I think (based on very little MS-SQL experience) the cursor in an sproc would be cleaner, I've googled various cursor examples but have not found a similar example that I can use to learn from.
Your input is greatly appreciated.
Thanks