Click here to Skip to main content
15,896,269 members
Home / Discussions / Database
   

Database

 
GeneralRe: Totaling previous months figures Pin
Muammar©20-Jun-09 3:15
Muammar©20-Jun-09 3:15 
GeneralRe: Totaling previous months figures Pin
Henry Minute20-Jun-09 1:00
Henry Minute20-Jun-09 1:00 
AnswerRe: Totaling previous months figures Pin
Niladri_Biswas22-Jun-09 20:54
Niladri_Biswas22-Jun-09 20:54 
GeneralRe: Totaling previous months figures Pin
Muammar©22-Jun-09 22:47
Muammar©22-Jun-09 22:47 
GeneralRe: Totaling previous months figures Pin
Niladri_Biswas30-Jun-09 7:01
Niladri_Biswas30-Jun-09 7:01 
GeneralRe: Totaling previous months figures Pin
Muammar©30-Jun-09 8:02
Muammar©30-Jun-09 8:02 
QuestionSP to record inputs plus random records from 2nd table Pin
munklefish19-Jun-09 5:13
munklefish19-Jun-09 5:13 
AnswerRe: SP to record inputs plus random records from 2nd table Pin
Niladri_Biswas22-Jun-09 22:40
Niladri_Biswas22-Jun-09 22:40 
Your question is not very clear, because

a) You never specified if the data in TableA has been inserted already and

then you want to update the 6th column of TableA [ As you

specified that the first 5 fields of TableA will have values supplied from

the Stored Proc which indicates that the 6th column will have values from

TableB
] with the values from TableB.

b) The Table Structure of both the tables are absent.

c) What will be the ultimate output [ Any rough sketch will make the

picture more clear]

d) Whether Table2's column will have predefined value or not. If not

whether the values needs to be inserted at runtime in TableB and then it

has to be fetched and next to be inserted in TableA?

e) Any dependency is lying between the two tables(e.g. Referential

Integrity Constraint)

However, I am assuming that TableA has the following structure

TableA

Col1 Col2 Col3 Col4 Col5 Col6


All are Varchar(50) types.

N.B.~ Col6 will have the value from TableB

TableB

RandomCol


Again Varchar(50)

And my Stored Proc is as under:

ALTER PROCEDURE InsertRecordsIntoTableA
	-- Add the parameters for the stored procedure here
	(
		@VarCol1 AS VARCHAR(50),
		@VarCol2 AS VARCHAR(50),
		@VarCol3 AS VARCHAR(50),
		@VarCol4 AS VARCHAR(50),
		@VarCol5 AS VARCHAR(50)
	)
AS
BEGIN
	
	-- VARIABLE DECLARATION
	DECLARE @RANDOMCOLUMNVALUES VARCHAR(50)

   -- STEP 1: DECLARE A CURSOR
	DECLARE MYRANDOMCURSOR CURSOR FOR

		SELECT    RANDOMCOL
		FROM      TABLEB

	-- STEP 2: OPEN THE CURSOR
	OPEN MYRANDOMCURSOR 

	FETCH MYRANDOMCURSOR INTO @RANDOMCOLUMNVALUES

	-- STEP 3: START THE LOGIC

	WHILE @@Fetch_Status = 0

	BEGIN

		-- STEP 4: INSERT THE COMBINED RECORDS INTO TABLE A

			INSERT INTO TABLEA(COL1,COL2,COL3,COL4,COL5,COL6)

			VALUES(@VarCol1,@VarCol2,@VarCol3,@VarCol4,@VarCol5,@RANDOMCOLUMNVALUES)
		
	-- STEP 5: GET THE NEXT RECORD
	FETCH MYRANDOMCURSOR INTO @RANDOMCOLUMNVALUES           

   END

	--STEP 6: CLOSE THE CURSOR
	CLOSE MYRANDOMCURSOR

	--STEP 6: DEALLOCATE THE CURSOR
	DEALLOCATE MYRANDOMCURSOR
	
END


Hope this answers you question.

If not, please tell your problem precisely with necessary

description


It can even be solved without using CURSOR and with a while loop

Please be specific about your question so that others can understand

properly.
Smile | :)

Niladri Biswas

QuestionHelps on this Convertion Problem Pin
Vimalsoft(Pty) Ltd19-Jun-09 3:49
professionalVimalsoft(Pty) Ltd19-Jun-09 3:49 
AnswerRe: Helps on this Convertion Problem Pin
DoctorMick19-Jun-09 5:37
DoctorMick19-Jun-09 5:37 
GeneralRe: Helps on this Convertion Problem Pin
Vimalsoft(Pty) Ltd19-Jun-09 5:38
professionalVimalsoft(Pty) Ltd19-Jun-09 5:38 
QuestionTable Transfer Pin
Paul Unsworth19-Jun-09 3:38
Paul Unsworth19-Jun-09 3:38 
AnswerRe: Table Transfer Pin
Mycroft Holmes20-Jun-09 0:13
professionalMycroft Holmes20-Jun-09 0:13 
GeneralRe: Table Transfer Pin
Paul Unsworth21-Jun-09 21:32
Paul Unsworth21-Jun-09 21:32 
GeneralRe: Table Transfer Pin
Mycroft Holmes21-Jun-09 22:03
professionalMycroft Holmes21-Jun-09 22:03 
Questionmultiple language problem with access database Pin
abhijit1234519-Jun-09 2:25
abhijit1234519-Jun-09 2:25 
QuestionRe: multiple language problem with access database Pin
Eddy Vluggen19-Jun-09 3:16
professionalEddy Vluggen19-Jun-09 3:16 
GeneralSQL Server Search Critiera.................... Pin
Isaac Gordon18-Jun-09 19:18
Isaac Gordon18-Jun-09 19:18 
GeneralRe: SQL Server Search Critiera.................... Pin
_Damian S_18-Jun-09 19:47
professional_Damian S_18-Jun-09 19:47 
GeneralRe: SQL Server Search Critiera.................... Pin
Isaac Gordon18-Jun-09 20:05
Isaac Gordon18-Jun-09 20:05 
GeneralRe: SQL Server Search Critiera.................... Pin
Ashfield18-Jun-09 21:22
Ashfield18-Jun-09 21:22 
GeneralRe: SQL Server Search Critiera.................... Pin
Isaac Gordon19-Jun-09 0:06
Isaac Gordon19-Jun-09 0:06 
GeneralRe: SQL Server Search Critiera.................... Pin
Ashfield19-Jun-09 5:14
Ashfield19-Jun-09 5:14 
GeneralRe: SQL Server Search Critiera.................... Pin
Isaac Gordon19-Jun-09 21:16
Isaac Gordon19-Jun-09 21:16 
GeneralRe: SQL Server Search Critiera.................... Pin
Ashfield20-Jun-09 6:22
Ashfield20-Jun-09 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.