Solved

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

Posted on 2011-03-03
7
274 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now