Solved

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

Posted on 2011-03-03
7
279 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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
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 …

739 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