Kuyo Kuyo -5 years ago 134
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 Source
INSERT INTO [dbo].[registration] 
SELECT a.studentid, 
FROM   [dbo].[student] AS a 
WHERE  [email] = @Email; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download