?
Solved

Help with SQL Query

Posted on 2009-05-12
5
Medium Priority
?
211 Views
Last Modified: 2012-05-06
I have a table EXAMINATION_QUESTIONS and a table EXAMINATION_SCHEDULER.

I wish to populate table SCHEDULER with records from a table EXAMINATION_QUESTIONS Using a conditional query.

Table EXAMINATION_QUESTIONS  needs to be populated with 2 extra column which are not present in table which is giving me the problem.

I have enclosed a query which i build and i am sure that there is some syntax in the query i am using.

ID,

CREATE PROCEDURE [dbo].[ExamMode_SetupExamQuestionforTestTaker]
(
	@REF_CODE nvarchar(50),
	@PROCESS_FLAG_ID int,
	@REQUESTOR_ID int,
	@TEST_TAKER_ID int
)
AS
SET NOCOUNT ON;
 
 
INSERT INTO EXAMINATION_SCHEDULER
(
	REQUESTOR_ID,
	EXAM_REFERENCE_CODE,
	TEST_TAKER_ID,
	QUESTION_ID,
	CORRECT_ANSWER_ID,
	MARK_ALLOCATED,
	CREATE_DATE
)
 
VALUES
(
	@REQUESTOR_ID,
	@TEST_TAKER_ID,
	SELECT
		EXAM_REFERENCE_CODE,
		QUESTION_ID,
		CORRECT_ANSWER_ID,
		MARK_ALLOCATED,
		CREATE_DATE
	FROM
		EXAMINATION_QUESTIONS
	WHERE 
		EXAM_REFERENCE_CODE=@REF_CODE  
)

Open in new window

0
Comment
Question by:TECH_NET
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24369066
Hello TECH_NET,

CREATE PROCEDURE [dbo].[ExamMode_SetupExamQuestionforTestTaker]
(
      @REF_CODE nvarchar(50),
      @PROCESS_FLAG_ID int,
      @REQUESTOR_ID int,
      @TEST_TAKER_ID int
)
AS
SET NOCOUNT ON;
 
 
INSERT INTO EXAMINATION_SCHEDULER
(
      REQUESTOR_ID,
      EXAM_REFERENCE_CODE,
      TEST_TAKER_ID,
      QUESTION_ID,
      CORRECT_ANSWER_ID,
      MARK_ALLOCATED,
      CREATE_DATE
)
 
      SELECT    @REQUESTOR_ID,
                  @TEST_TAKER_ID,
                  EXAM_REFERENCE_CODE,
                  QUESTION_ID,
                  CORRECT_ANSWER_ID,
                  MARK_ALLOCATED,
                  CREATE_DATE
      FROM
            EXAMINATION_QUESTIONS
      WHERE
            EXAM_REFERENCE_CODE=@REF_CODE  

GO


Regards,

Aneesh
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 24369072
Here you go.
CREATE PROCEDURE [dbo].[ExamMode_SetupExamQuestionforTestTaker]
(
        @REF_CODE nvarchar(50),
        @PROCESS_FLAG_ID int,
        @REQUESTOR_ID int,
        @TEST_TAKER_ID int
)
AS
SET NOCOUNT ON;
 
 
INSERT INTO EXAMINATION_SCHEDULER
(
        REQUESTOR_ID,
        EXAM_REFERENCE_CODE,
        TEST_TAKER_ID,
        QUESTION_ID,
        CORRECT_ANSWER_ID,
        MARK_ALLOCATED,
        CREATE_DATE
)
 
        SELECT
        @REQUESTOR_ID,
        @TEST_TAKER_ID,
                EXAM_REFERENCE_CODE,
                QUESTION_ID,
                CORRECT_ANSWER_ID,
                MARK_ALLOCATED,
                CREATE_DATE
        FROM
                EXAMINATION_QUESTIONS
        WHERE 
                EXAM_REFERENCE_CODE=@REF_CODE  

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24369075
close:
CREATE PROCEDURE [dbo].[ExamMode_SetupExamQuestionforTestTaker]
(
      @REF_CODE nvarchar(50),
      @PROCESS_FLAG_ID int,
      @REQUESTOR_ID int,
      @TEST_TAKER_ID int
)
AS
SET NOCOUNT ON;
 
 
INSERT INTO EXAMINATION_SCHEDULER
(
      REQUESTOR_ID,
      EXAM_REFERENCE_CODE,
      TEST_TAKER_ID,
      QUESTION_ID,
      CORRECT_ANSWER_ID,
      MARK_ALLOCATED,
      CREATE_DATE
)
 
SELECT
      @REQUESTOR_ID,
      @TEST_TAKER_ID,
            EXAM_REFERENCE_CODE,
            QUESTION_ID,
            CORRECT_ANSWER_ID,
            MARK_ALLOCATED,
            CREATE_DATE
      FROM
            EXAMINATION_QUESTIONS
      WHERE 
            EXAM_REFERENCE_CODE=@REF_CODE  
)

Open in new window

0
 

Author Comment

by:TECH_NET
ID: 24370311
I have a follow up question.

I get the following error when i execute the stored procedure from my .net program.

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

I had to insert a COMMIT statement at the end of the sql query in the stored procedure to ensure the records are commited.

It is strange that the without the commit statement i do not see the inserted records although the identity column in being incremented.

Any thoughts why the above error is occuring.
0
 

Author Comment

by:TECH_NET
ID: 24370345
I had it fixed. I forgot a Begin transaction statement
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question