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.
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 PhoneNo1 AAA 123-456-45872 AAA 123-456-45883 AAA 123-456-45894 AAA 123-456-45905 AAA 123-456-45916 AAA 123-456-45927 AAA 123-456-45938 AAA 123-456-45949 AAA 123-456-459510 AAA 123-456-4596and i want a result like this...--My First TableID BussName PhoneNo1 AAA 123-456-45872 AAA 123-456-45883 AAA 123-456-45894 AAA 123-456-45905 AAA 123-456-4591--My Second TableID BussName PhoneNo6 AAA 123-456-45927 AAA 123-456-45938 AAA 123-456-45949 AAA 123-456-459510 AAA 123-456-4596any help with this...coz im tired of using my simple query...like Select * from MyTable where [ID] Between 1 and 5Select * from MyTable where [ID] Between 6 and 10thanks 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" |
|
|
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... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 05:53:00
|
so you want 5 records grouped always? |
|
|
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 5Select * from MyTable where [ID] BETWEEN 6 and 10because every time i split i change this (BETWEEN no. AND no.) just to have my desired grouping or spliting... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 06:32:38
|
then just create a sp like belowCREATE PROC GetDataWIthinRange@Start int,@End intASSELECT *FROM YourTableWHERE ID BETWEEN @Start AND @EndGO then just call EXEC GetDataWIthinRange 1,10EXEC GetDataWithinRange 20,25.. |
|
|
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... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 09:18:03
|
something likeCREATE PROC GetDataWIthinRange@Count int,@Batch intASDECLARE @Min int,@Max intSELECT @Min=MIN(ID),@Max=MAX(ID)FROM YourTableSELECT *FROM YourTableWHERE ID BETWEEN @Min+(@Count*(@Batch-1)) AND (@Min-1)+(@Count*@Batch)GO |
|
|
HardHabit
Starting Member
12 Posts |
Posted - 2008-11-23 : 20:57:49
|
thanks guys for helping me on this one. :) :) :) |
|
|
|
|
|