Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear everyone,
I have the issue that i don't know how to insert into a table from another table with some additional data like this:
Table Student
ID| Name
01| Jimmy
02| Tom
....( a lot data).....

Table Result
ID|Name|Course|Result
01|01 |Math | A+
02|02 |Lit | C
...( a lot data).....

Table Courses
ID |CourseName |Price
Math|Mathematics | 15$
Lit |Literature | 20$
......(a lot data).......

I want to add into Result like this,and i knew the 'Kate' student must be added 10 courses more:
SQL
insert into result(ID, Name,Course) select * from Course with ID=10000 and name='Kate'

But i know there is no way like that in SQl.

Is there anyway so that we can insert into table from another table with some variables, without using function and store?

I am using sql 2005.

Really have no idea.
Please give me ur hands or just a little of hints!
Thank in advance.
Sincerely.
Toki.
Posted
Updated 5-Apr-15 13:53pm
v2
Comments
Peter Leow 5-Apr-15 8:50am    
Not clear.
I observed that your table structure does not look right. For example, if the name field in the result table is for student name then it should be removed as it has no place there, it belongs to student table (which rightfully already has that).
How do you know what courses to add for kate? Does this information exist in any tables?
Tokisan 5-Apr-15 19:51pm    
you are right, but what i need is how to insert.
Thank a lot and please forgive my rude and my mistaken.

1 solution

You could try and achieve this logic by using a stored procedure.
However, if you want to add additional records, it will not be possible without writing more insert statements.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900