Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-03
7
Medium Priority
?
287 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 2000 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
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!

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression

610 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