Solved

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

Posted on 2011-03-03
7
277 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

828 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