Stored procedure to insert field value that have other fields from other table

DARK__FOXX

Member
Joined
Sep 2, 2020
Messages
9
Programming Experience
Beginner
Hi,

I have this new empty table that have eight field called Table-X and an existing table called Table_Y with different fields .
In the store procedure I am only interested three fields that I have to insert into the table ,but two fields are the fields of table_Y
My question is how do I insert these fields into the new empty table that are also different name fields?

This is my first approach:

VB.NET:
@ID_CUSTOMER int,
@COMPANY_NAME varchar(50),
@EXP_DATE date,

AS

BEGIN
INSERT INTO TABLE_X
                (
                ID_CUSTOMER,
                COMPANY_NAME,
                EXP_DATE,
                
                )

 //add SELECT here?              
 
VALUES(
  
 @ID_CUSTOMER,
 @COMPANY_NAME,
@EXP_DATE,
 
 
 )
END
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,350
Location
Sydney, Australia
Programming Experience
10+
I've never actually tried this sort of thing myself but I would expect that you should be able to do something like this:
SQL:
INSERT INTO TableA (Column1A, Column2A, Column3)
SELECT Column1B, Column2B, @Column3Parameter
FROM TableB
WHERE Id = @IdParameter
 
Top Bottom