Kuyo Kuyo - 4 months ago 12
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?

INSERT INTO [dbo].[registration] 
SELECT a.studentid, 
FROM   [dbo].[student] AS a 
WHERE  [email] = @Email;