Solved

how can i execute this queries using stored procedure (including for loop) ??

Posted on 2011-03-03
7
280 Views
Last Modified: 2012-05-11
here i tell u the table definition and inster queries ..

create table Details ( 
    uid     int  IDENTITY  NOT NULL,
    uname   varchar(10) not null,
    pwd     varchar(10) not null,
    email varchar(20) not null,
    login_time datetime not null,
    Questions varchar(200) not null,
    correctOpt varchar(50) not null,
    logout_time datetime not null,
    comment varchar(100) null
); 

insert into Details values ('Admin','Admin', 'info@rubikube.com','2011-02-14 17:42:12.983','hi admin how r u ?','1c','2011-02-14 17:44:20.810','busy person')
insert into Details values ('Parth','Shah', 'parth.parth48@hotmail.com','2011-02-14 17:42:12.983','hi admin how r u ?','1c','2011-02-14 17:44:20.810','busy person')
insert into Details values ('Atul','Patel', 'atul.patel@hotmail.com','2011-02-14 17:42:12.983','hi admin how r u ?','1c','2011-02-14 17:44:20.810','busy person')

Open in new window


now instead of these 3 insert queries i want to use for loop in stored procedure and insert data into table ..

mention : only Questions and correct options can be changed , remaining will be same ..

how can i do that ??
0
Comment
Question by:Parth48
[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
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35025458
You mean you want to loop calling a stored procedure, or you want to loop within a stored procedure?
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 35025561
I am also not clear about what you are actually trying to do.

If you are asking about how to save new question without repeadly specifying the values again in query, since it is the same and Question and correctOpt will only differ, try this stored procedure

CREATE PROCEDURE usp_SaveNewQuestion
    (
      @uid INT ,
      @Question VARCHAR(200) ,
      @correctOpt VARCHAR(50)
    )
AS 
    BEGIN

        INSERT  INTO Details
                SELECT  uname ,
                        pwd ,
                        email ,
                        login_time ,
                        @Question ,
                        @correctOpt ,
                        logout_time ,
                        comment
                FROM    Details
                WHERE   uid = @uid
        

    END
GO

Open in new window

To save a new question and option. For eg:-
EXEC usp_SaveNewQuestion 2, 'Hi admin, are you fine ?', '1b'

Open in new window


This will insert a new record with user details having userid (uid) = 2 with new question and option

If this is NOT, please explain us clearly

Raj

0
 

Author Comment

by:Parth48
ID: 35025740
yes @RajkumarGS:u r right .....

but how can i use for loop in your code or without for loop i can do it ??
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35025782

For eg:- Are you trying to save 3 questions and correctOpt at a time ?
0
 

Author Comment

by:Parth48
ID: 35026088
yes i want to save 3 question and correctOpt at a time ...

what can i do ??
0
 

Author Comment

by:Parth48
ID: 35026484
i have string array for questions and CorrectOpt , so using for loop it will be easy to insert .....

so how can i do it ??
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35037630
Glad I could assist you.

I am on leave and at home now.

Just saw your replies.

If you have any more queries, please post your question

Raj
0

Featured Post

Technology Partners: 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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

690 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