Solved

Help with SQL Query

Posted on 2009-05-12
5
175 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
5 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now