Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 HELP WITH SPLITING DATA

Author  Topic 

HardHabit
Starting Member

12 Posts

Posted - 2008-11-20 : 04:19:29
Can any one help me with this problem...i want to split my data according to want i need....sample i want to split it by 5, 10 etc....

I got a table like this...
ID BussName PhoneNo
1 AAA 123-456-4587
2 AAA 123-456-4588
3 AAA 123-456-4589
4 AAA 123-456-4590
5 AAA 123-456-4591
6 AAA 123-456-4592
7 AAA 123-456-4593
8 AAA 123-456-4594
9 AAA 123-456-4595
10 AAA 123-456-4596

and i want a result like this...

--My First Table
ID BussName PhoneNo
1 AAA 123-456-4587
2 AAA 123-456-4588
3 AAA 123-456-4589
4 AAA 123-456-4590
5 AAA 123-456-4591

--My Second Table
ID BussName PhoneNo
6 AAA 123-456-4592
7 AAA 123-456-4593
8 AAA 123-456-4594
9 AAA 123-456-4595
10 AAA 123-456-4596

any help with this...coz im tired of using my simple query...like

Select * from MyTable where [ID] Between 1 and 5

Select * from MyTable where [ID] Between 6 and 10

thanks in advance...










SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-20 : 04:24:31
You want multiple tables, or pagination?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

HardHabit
Starting Member

12 Posts

Posted - 2008-11-20 : 04:31:15
can i have both so i can figure out what is the best...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-20 : 05:53:00
so you want 5 records grouped always?
Go to Top of Page

HardHabit
Starting Member

12 Posts

Posted - 2008-11-20 : 06:20:25
no, i just use it as my sample...my data contain hundred or thousand its time consuming if i use the code

Select * from MyTable where [ID] BETWEEN 1 and 5
Select * from MyTable where [ID] BETWEEN 6 and 10

because every time i split i change this (BETWEEN no. AND no.) just to have my desired grouping or spliting...






Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-20 : 06:32:38
then just create a sp like below

CREATE PROC GetDataWIthinRange
@Start int,
@End int
AS
SELECT *
FROM YourTable
WHERE ID BETWEEN @Start AND @End
GO


then just call EXEC GetDataWIthinRange 1,10
EXEC GetDataWithinRange 20,25..
Go to Top of Page

HardHabit
Starting Member

12 Posts

Posted - 2008-11-20 : 06:48:13
yes that's one of my option creating an SP..is there any way that i put one variable (ex. 100) and my data would be splitted into 100...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-20 : 09:18:03
something like
CREATE PROC GetDataWIthinRange
@Count int,
@Batch int
AS
DECLARE @Min int,@Max int

SELECT @Min=MIN(ID),
@Max=MAX(ID)
FROM YourTable

SELECT *
FROM YourTable
WHERE ID BETWEEN @Min+(@Count*(@Batch-1)) AND (@Min-1)+(@Count*@Batch)
GO
Go to Top of Page

HardHabit
Starting Member

12 Posts

Posted - 2008-11-23 : 20:57:49
thanks guys for helping me on this one. :) :) :)
Go to Top of Page
   

- Advertisement -