KH LIM KH LIM - 4 months ago 9
SQL Question

How I can copy ID from table A to table B

This is SQL code:

Declare @A_ID AS A_ID

insert into TBL_FO VALUES(NEWID(), @A_ID, '30000.00','1','1')
(select * from TBL_DETAIL where A_ID = '59366409-2EB6-49BC-A88F-801692B735D6')



  1. I want to follow or copy the A_ID from TBL_DETAIL as
    '59366409-2EB6-49BC-A88F-801692B735D6'
    to TBL_FO for
    @A_ID
    .. How I can declare the A_ID for copy the same ID


Answer

Try this:

Declare @A_ID  as varchar(100) -- adjust the length as needed
select @A_ID = A_ID from TBL_DETAIL where A_ID = '59366409-2EB6-49BC-A88F-801692B735D6'

insert into TBL_FO VALUES(NEWID(), @A_ID, '30000.00','1','1')