Hi @Ruhul-0167,
The following method can also not create an intermediate table in advance:
Create Table Gifts (
FName varchar (50) NOT NULL,
LName varchar (50) NOT NULL,
Project varchar (50) NOT NULL,
Amount decimal NOT NULL,
TransactionDate Datetime NOT NULL,
TransId int NOT NULL,
GiftImportId varchar (20) NUll
)
Insert into Gifts values ('Adam', 'Smith', 'Water for life', 15, GETDATE(), 4000, NULL)
Insert into Gifts values ('Chris', 'Gayle', 'Orphans and Children', 10, GETDATE(), 4001, NULL)
Insert into Gifts values ('Chris', 'Gayle', 'Emergency Response', 10, GETDATE(), 4001, NULL)
Insert into Gifts values ('Chris', 'Gayle', 'Where Most Needed', 30, GETDATE(), 4001, NULL)
Insert into Gifts values ('David', 'Warner', 'Winter Appeal', 20, GETDATE(), 4002, NULL)
Insert into Gifts values ('Ahmed', 'Sabil', 'Global Coronavirus Appeal', 10, GETDATE(), 4003, NULL)
Insert into Gifts values ('Ahmed', 'Sabil', 'Emergency Response', 30, GETDATE(), 4003, NULL)
SELECT DISTINCT TransID,GiftImportId
INTO #Test
FROM Gifts
UPDATE #Test
SET GiftImportId = CONVERT(char(20), CRYPT_GEN_RANDOM(10),2)
UPDATE G
SET GiftImportId = T.GiftImportId
FROM Gifts G
JOIN #Test T
ON G.TransID=T.TransID
SELECT * FROM Gifts
DROP TABLE #Test
DROP TABLE Gifts
Output:
FName LName Project Amount TransactionDate TransId GiftImportId
Adam Smith Water for life 15 2020-12-14 15:41:34.430 4000 FC633C2446CDF3EEC775
Chris Gayle Orphans and Children 10 2020-12-14 15:41:34.430 4001 52E03A2A575D7A0F7CA3
Chris Gayle Emergency Response 10 2020-12-14 15:41:34.430 4001 52E03A2A575D7A0F7CA3
Chris Gayle Where Most Needed 30 2020-12-14 15:41:34.430 4001 52E03A2A575D7A0F7CA3
David Warner Winter Appeal 20 2020-12-14 15:41:34.430 4002 ED4582CF0489933585CD
Ahmed Sabil Global Coronavirus Appeal 10 2020-12-14 15:41:34.430 4003 DF4ABDA2D3BA5D4BA2B9
Ahmed Sabil Emergency Response 30 2020-12-14 15:41:34.430 4003 DF4ABDA2D3BA5D4BA2B9
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Regards
Echo
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues November--What can I do if my transaction log is full?
Hot issues November--How to convert Profiler trace into a SQL Server table