September 7, 2012 at 5:38 am
Hi,
we are having one table (AA) with 3 columns
Id,Polcinumber,date
1,s1234,04/09/2012
2,s2345,05/06/2012
we are having another table(BB) having 2 cloumns
Id,Policynumber,date
1,s71234, currentdate
we are inserting the records from BB to AA table.in AA table the values of Polcynumbers are already existing
i want write the query to replace the oldpolicynumbers
can any one help on this
September 7, 2012 at 5:44 am
assuming the ID is the join criteria between the two tables, this will do it:
UPDATE AA
SET AA.Polcinumber = BB.Policynumber
FROM BB
WHERE AA.ID = BB.ID
AND AA.Polcinumber <> BB.Policynumber
Lowell
September 7, 2012 at 6:17 am
Thanks Lowel,
how to insert the currentdate into AA table with new policy number
September 7, 2012 at 6:41 am
Div Goud (9/7/2012)
Thanks Lowel,how to insert the currentdate into AA table with new policy number
just expand the number of columns being updated;
...
SET AA.Polcinumber = BB.Policynumber,
Column2 = GetDate(), --a function fromt eh server
Column3 = 'Approved', --a static value
Column4 = BB.SomeOtherColumn -- a value in the other table
Lowell
September 7, 2012 at 6:43 am
DELETE aa
FROM aa
INNER JOIN bb
ON bb.ID = aa.ID
SET IDENTITY_INSERT aa ON
INSERT INTO aa (Id,Policynumber,date)
SELECT Id,Policynumber,date
FROM bb
SET IDENTITY_INSERT aa OFF
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply