Click here to Skip to main content
15,899,679 members
Home / Discussions / Database
   

Database

 
QuestionMDB opened indication Pin
udikantz1-Jul-09 0:05
udikantz1-Jul-09 0:05 
AnswerRe: MDB opened indication Pin
paas1-Jul-09 1:46
paas1-Jul-09 1:46 
AnswerRe: MDB opened indication Pin
Branislav Vidovic1-Jul-09 3:54
Branislav Vidovic1-Jul-09 3:54 
GeneralRe: MDB opened indication Pin
udikantz1-Jul-09 4:45
udikantz1-Jul-09 4:45 
GeneralRe: MDB opened indication Pin
David Skelly1-Jul-09 6:17
David Skelly1-Jul-09 6:17 
GeneralRe: MDB opened indication Pin
riced2-Jul-09 7:09
riced2-Jul-09 7:09 
QuestionSplitting Rows in SQL Server 2005 Pin
rajanandal30-Jun-09 19:04
rajanandal30-Jun-09 19:04 
AnswerRe: Splitting Rows in SQL Server 2005 [modified] Pin
Niladri_Biswas30-Jun-09 20:02
Niladri_Biswas30-Jun-09 20:02 
Try this(Assuming that the original table name is tblSENTBYSENTON)

ALTER PROCEDURE dbo.GETRECORDS
	-- Add the parameters for the stored procedure here
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

   -- VARIABLE DECLARATION
	DECLARE @SENTBY INT
	DECLARE @SENTON DATETIME
	DECLARE @ACCEPTBY INT
	DECLARE @ACCEPTON DATETIME

	DECLARE @NEWTBLSENTBYSENTON TABLE 
	(
		SENTBY INT,
		SENTON DATETIME
	)

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

		SELECT    SENTBY,SENTON,ACCEPTBY,ACCEPTON
		FROM      TBLSENTBYSENTON

	-- STEP 2: OPEN THE CURSOR
	OPEN MYCURSOR 

	FETCH MYCURSOR INTO @SENTBY,@SENTON,@ACCEPTBY,@ACCEPTON

	-- STEP 3: START THE LOGIC

	WHILE @@Fetch_Status = 0

	BEGIN

		-- STEP 4: INSERT RECORDS INTO TABLE @NEWTBLSENTBYSENTON
		--		   BASED ON THE LOGIC PROVIDED

			IF(@SENTBY = @ACCEPTBY)

			BEGIN
				INSERT INTO @NEWTBLSENTBYSENTON(SENTBY,SENTON)
				VALUES(@SENTBY,@SENTON)
			END

			ELSE

			BEGIN

				INSERT INTO @NEWTBLSENTBYSENTON(SENTBY,SENTON)
				VALUES(@SENTBY,@SENTON)

				INSERT INTO @NEWTBLSENTBYSENTON(SENTBY,SENTON)
				VALUES(@ACCEPTBY,@ACCEPTON)
			END

	
	-- STEP 5: GET THE NEXT RECORD
	FETCH MYCURSOR INTO @SENTBY,@SENTON,@ACCEPTBY,@ACCEPTON           

   END

	--STEP 6: CLOSE THE CURSOR
	CLOSE MYCURSOR

	--STEP 7: DEALLOCATE THE CURSOR
	DEALLOCATE MYCURSOR
	
	SELECT * FROM @NEWTBLSENTBYSENTON
END


With the same input, I got the same output:

Sentby		SentOn 
1	2009-06-15 19:40:36.000	
32	2009-06-29 13:36:59.450	
1	2009-06-30 12:25:45.303
1	2009-06-15 19:40:36.000	
1	2009-06-16 13:19:34.693	
1	2009-06-15 19:40:36.000	
2	2009-06-15 19:40:36.000	
1	2009-06-16 19:40:36.000


Hope this helps.
Smile | :)

Niladri Biswas

modified on Wednesday, July 1, 2009 2:11 AM

GeneralRe: Splitting Rows in SQL Server 2005 Pin
rajanandal30-Jun-09 20:32
rajanandal30-Jun-09 20:32 
GeneralRe: Splitting Rows in SQL Server 2005 [modified] Pin
Niladri_Biswas30-Jun-09 20:45
Niladri_Biswas30-Jun-09 20:45 
AnswerRe: Splitting Rows in SQL Server 2005 [modified] Pin
rajanandal30-Jun-09 20:53
rajanandal30-Jun-09 20:53 
GeneralGreen Screen Studio Pin
atlas2130-Jun-09 17:07
atlas2130-Jun-09 17:07 
GeneralRe: Green Screen Studio Pin
Mycroft Holmes30-Jun-09 17:49
professionalMycroft Holmes30-Jun-09 17:49 
GeneralRe: Green Screen Studio Pin
Jerry Hammond1-Jul-09 3:44
Jerry Hammond1-Jul-09 3:44 
QuestionRandom Access to DB Pin
LucBite30-Jun-09 4:26
LucBite30-Jun-09 4:26 
AnswerRe: Random Access to DB Pin
David Mujica30-Jun-09 4:48
David Mujica30-Jun-09 4:48 
AnswerRe: Random Access to DB [modified] Pin
Niladri_Biswas30-Jun-09 4:53
Niladri_Biswas30-Jun-09 4:53 
QuestionSQL server 2003 Pin
jamith30-Jun-09 2:52
jamith30-Jun-09 2:52 
AnswerRe: SQL server 2003 Pin
Jerry Hammond30-Jun-09 13:25
Jerry Hammond30-Jun-09 13:25 
AnswerRe: SQL server 2003 Pin
Mycroft Holmes30-Jun-09 17:51
professionalMycroft Holmes30-Jun-09 17:51 
QuestionSQL 2005 Replication Pin
Abdul Rahman Hamidy30-Jun-09 2:29
Abdul Rahman Hamidy30-Jun-09 2:29 
Generaldatabase Performance...... Pin
Isaac Gordon29-Jun-09 23:59
Isaac Gordon29-Jun-09 23:59 
GeneralRe: database Performance...... Pin
Blue_Boy30-Jun-09 0:15
Blue_Boy30-Jun-09 0:15 
GeneralRe: database Performance...... Pin
Niladri_Biswas30-Jun-09 0:26
Niladri_Biswas30-Jun-09 0:26 
GeneralRe: database Performance...... Pin
Isaac Gordon30-Jun-09 0:33
Isaac Gordon30-Jun-09 0:33 

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.