Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
SELECT     subject.PaperName, subject.Marks
FROM         course INNER JOIN
                      ids ON course.Courseno = ids.Courseno INNER JOIN
                      subject ON ids.PaperID = subject.PaperID
                      INTO result;



Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'INTO'.
This is the error I am getting. I basically want to store the result of the query into a new table.
Posted

Try this:

1.
SQL
SELECT subject.PaperName
	 , subject.Marks
FROM
	course
	INNER JOIN
		ids
		ON course.Courseno = ids.Courseno
	INNER JOIN
		subject
		ON ids.PaperID = subject.PaperID
                      INTO TABLE result;

2.
SQL
 INSERT INTO result
SELECT subject.PaperName
	 , subject.Marks
FROM
	course
	INNER JOIN
		ids
		ON course.Courseno = ids.Courseno
	INNER JOIN
		subject
		ON ids.PaperID = subject.PaperID


3.
SQL
SELECT subject.PaperName
	 , subject.Marks
	 INTO result
FROM
	course
	INNER JOIN
		ids
		ON course.Courseno = ids.Courseno
	INNER JOIN
		subject
		ON ids.PaperID = subject.PaperID
 
Share this answer
 
Comments
codingisok101 24-Aug-12 7:00am    
Solution 3 worked! Thanks!
Prasad_Kulkarni 24-Aug-12 7:01am    
You're welcome!
Try with this:

SQL
SELECT subject.PaperName, subject.Marks  INTO result   
FROM   course INNER JOIN
                      ids ON course.Courseno = ids.Courseno INNER JOIN
                      subject ON ids.PaperID = subject.PaperID
                      ;


the syntax is SELECT ... INTO...FROM.

Hope this helps
 
Share this answer
 
Comments
codingisok101 24-Aug-12 6:59am    
yep that was the mistake! Incorrect order! Thanks a lot!
I.explore.code 24-Aug-12 7:09am    
cheers mate!

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