Wednesday, March 7, 2012

INSERT QUERY!

Hi all,
I am attempting to populate a table with the results of the following
queries.
Unsure of what syntax is required.
Help appreciated!!!!
INSERT INTO [Question] (ExamID, Question, Idx) ?
(SELECT MAX(ExamID) FROM [EasyLearning].[dbo].[Exam]),
(SELECT ex2_mult_Q FROM exam2 WHERE ex2_name = @.ExamName),
(SELECT Idx FROM Exam WHERE ExamID = (SELECT MAX(ExamID) FROM
[EasyLearning].[dbo].[Exam]) + 1)
Cheers AdamHi Adam,
INSERT INTO [Question] (ExamID, Question, Idx)
SELECT
(SELECT MAX(ExamID) FROM [EasyLearning].[dbo].[Exam]) AS ExamID,
(SELECT ex2_mult_Q FROM exam2 WHERE ex2_name = @.ExamName) AS
Question,
(SELECT Idx FROM Exam WHERE ExamID =
(
SELECT MAX(ExamID) FROM [EasyLearning].[dbo].[Exam]) + 1
)
) AS Idx
HTH, jens Suessmeyer.|||Look up INSERT.SELECT in Books Online, but start by building the SELECT quer
y
that returns all the values that you intend to insert.
Once the query returns the correct values, use it in the INSERT...SELECT
query.
If more than one row should be returned, make sure the values are properly
related - right now I see no relationship between the three selects - but if
you do, and it works as you expect, then that's good enough for me.
ML
http://milambda.blogspot.com/

No comments:

Post a Comment