Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am new to sql sever 2008 r2 . i was created stored procedure like this given below . i want to insert all the records but it was storing only one record

SQL
 create PROCEDURE [dbo].[StudentDEtails]
	-- Add the parameters for the stored procedure here
	@Id varchar(40)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE         @section			varchar(50),
			@Postion			varchar(50),
			@Rating				int,
			@marks				varchar(50),
			@Date		datetime,
			@Score			int,
			@class				varchar(50),
			@Signature		varchar(50),
			@Remarks			varchar(50),
			@subject_Types		varchar(50),
			@Initial_Grade		int,
			@strSQL				varchar(200),
                        @roll_Number              int,
			@xx                       int,
                        @yy                       int;
			
			
	DECLARE @MyCursor CURSOR; 

-- DELETE ALL EXISTING RECORDS FROM APPLICATION_FIRE
	TRUNCATE TABLE APPLICATION_FIRE;
	
-- Get Practice and Posttion
	
	SET @MyCursor = CURSOR FAST_FORWARD 
	FOR Select 	id,Date, Score, Initial_Grade, Class(i mean it is  1st class ,2rd class..etc ), signature,Remarks
	FROM DBO.sTudentinfo WHERE id = @id; 
			   	
	OPEN @MyCursor 
	FETCH NEXT FROM @MyCursor 
	INTO @id, @Date, @Score, @Initial_Grade, @Class, @Signature, @Remarks

	WHILE @@FETCH_STATUS = 0 
	BEGIN 
       
	    PRINT @Army_number
		PRINT @Section
		PRINT @Postion
		PRINT @rating
		PRINT @marks 
		PRINT @Date
		PRINT @Score
		PRINT @class
		PRINT @signature
		PRINT @Remarks
	        PRINT @Initial_grade
		PRINT @subject_Type
		
		-- GET PRACTICE, POSITION,rating,marks 
		SELECT @section = Type_Of_section, @Postion = Position, @rating = rating,@marks=marks,@subject_Types=subject_Types FROM DBO.studentmoreinfo WHERE yy_ID = @yy_Id AND
		roll_Number = @roll_Number AND xx_ID = @xx_ID;  
		
		
		
		
	   FETCH NEXT FROM @MyCursor 
	       INTO @id, @Date, @Score, @Initial_grade, @class, @signature, @Remarks
	
	 
  
	
END 

CLOSE @MyCursor 
DEALLOCATE @MyCursor 


this was excuting shows output like this

 1
 mar 7 2013 11:13 AM 
 0
 T.H
 1
 Af
 0
 
1

 
Mar 17 2013 11:13AM
1
0
2
fas
0
 
1

 
Mar 17 2013 11:13AM
0
0
3
fa
0
 
1
 
 
 
 
Mar 17 2013 11:13AM
1
0
2
fas
0


this oupt i want to sent to another table table name i s studentbasicinfo

i was wrote a query like this

SQL
insert into ([id],[section],[postion],[rating][marks][date][score],[class],[signature],[remarks],[subject_Types],[initila_grade]
values (@id,@section,@postion,@rating,@marks,@date,@Score,@calss,@signature,@remarks,@subject_Type,@initial_Grade)


this was excuted and it sotring only one row .Actuvally It has 3 row. iwant to sent all the row to that table how? so plz help me
Posted
Updated 19-Mar-13 22:11pm
v3
Comments
gvprabu 20-Mar-13 4:25am    
Hi Where u gave that Insert Statement..? Inside the loop means sure it will insert 3 Rows not one row...

1 solution

Hi Try This

SQL
CREATE PROCEDURE [dbo].[StudentDEtails]
	-- Add the parameters for the stored procedure here
	@Id varchar(40)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE   @section varchar(50), @Postion varchar(50),@Rating int, @marks varchar(50), @Date datetime,
			@Score int, @class varchar(50), @Signature varchar(50),@Remarks varchar(50),@subject_Types varchar(50),
			@Initial_Grade	int,@strSQL varchar(200),@roll_Number int,@xx int,@yy int;
			
	DECLARE @MyCursor CURSOR; 
 
-- DELETE ALL EXISTING RECORDS FROM APPLICATION_FIRE
	TRUNCATE TABLE APPLICATION_FIRE;
	
-- Get Practice and Posttion
	
	SET @MyCursor = CURSOR FAST_FORWARD 
	FOR Select id,Date, Score, Initial_Grade, Class(i mean it is  1st class ,2rd class..etc ), signature,Remarks
	FROM DBO.sTudentinfo WHERE id = @id; 
			   	
	OPEN @MyCursor 
	FETCH NEXT FROM @MyCursor 
	INTO @id, @Date, @Score, @Initial_Grade, @Class, @Signature, @Remarks
 
	WHILE @@FETCH_STATUS = 0 
	BEGIN 
	    PRINT @Army_number
		PRINT @Section
		PRINT @Postion
		PRINT @rating
		PRINT @marks 
		PRINT @Date
		PRINT @Score
		PRINT @class
		PRINT @signature
		PRINT @Remarks
	     PRINT @Initial_grade
		PRINT @subject_Type
		
		-- GET PRACTICE, POSITION,rating,marks 
		SELECT @section = Type_Of_section, @Postion = Position, @rating = rating,@marks=marks,@subject_Types=subject_Types FROM DBO.studentmoreinfo WHERE yy_ID = @yy_Id AND
		roll_Number = @roll_Number AND xx_ID = @xx_ID;  
		
	    insert studentbasicinfo into ([id],[section],[postion],[rating][marks][date][score],[class],[signature],[remarks],[subject_Types],[initila_grade]
	    values (@id,@section,@postion,@rating,@marks,@date,@Score,@calss,@signature,@remarks,@subject_Type,@initial_Grade)
		
	   FETCH NEXT FROM @MyCursor INTO @id, @Date, @Score, @Initial_grade, @class, @signature, @Remarks
    END 
 
    CLOSE @MyCursor 
    DEALLOCATE @MyCursor 
END

Regards,
GVPrabu
 
Share this answer
 
Comments
Member 9846414 20-Mar-13 6:41am    
thank u very much i got it . but here i am storing data into studentBasicinfo table for this table i want to write a qurey like this gievn below
select id,section, postion, rating, marks date, score, from studentbasicinfo where id='1'
group by id, section,postion,rating,narks,date,score this query were i should i write
help me plz this query must be excuted after above one can tell me plz
gvprabu 20-Mar-13 6:44am    
Hi,
Tel me one thing Why u need GROUP BY in your Query with out any Aggregate Function.
Member 9846414 22-Mar-13 6:59am    
thank u very much
Member 9846414 22-Mar-13 7:29am    
i was done thanku u very much replaying very soon .Hi can u help me for below link seeing. Actually what i am doing
http://www.codeproject.com/Questions/566062/howplustopluswirteplusaplusconditionplususingpluss

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900