Kuyo Kuyo - 5 months ago 26
SQL Question

Selecting row data from one table, then insert into another table using TableAdapter

I'm using TableAdapter Query Configuration Wizard. I want to select a data from one table and insert into another as shown in the statement below.

SELECT a.StudentID FROM [dbo].[Student] AS a WHERE [Email] = @Email;

INSERT INTO [dbo].[Registration] ([StudentID], [UniformOptionID], [Cost])
VALUES (a.StudentID, @Param1, @Param2);


When I call out the function on my application, The error message prompts:

Error message: The multi-part identifier "a.StudentID" could not be bound


Why is this not possible?

Answer
INSERT INTO [dbo].[registration] 
        ([studentid], 
         [uniformoptionid], 
         [cost]) 
SELECT a.studentid, 
   @Param1, 
   @Param2 
FROM   [dbo].[student] AS a 
WHERE  [email] = @Email;