Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
my Actual table
 
MIVID      Quantity         Value
------     ----------       --------
   1           10             3000
   1           20             3500
   1           15             2000
   2           20             3000
   2           50             7500
   3           25             2000
 
my requirement
 
 MIVID           Quantity        Value
 -------         ----------     ---------
   1                10             3000
   1                20             3500
   1                15             2000
 
 MIVID           Quantity        Value
 -------         ----------     ---------
   2                20             3000
   2                50             7500
 
MIVID           Quantity        Value
 -------         ----------     ---------
    3               25             2000
 
In asp.net how to split the table in to multiple tables based on column values.
Posted 28-Jun-13 7:09am
Edited 28-Jun-13 21:28pm
v3
Comments
Maciej Los at 28-Jun-13 12:19pm
   
What you mean "how to split table in to mulitple tables"?
ASP.NET? WinForms?
ProgramFOX at 28-Jun-13 12:22pm
   
ASP.NET (see subject: Table splitting in asp.net)
Maciej Los at 28-Jun-13 12:26pm
   
I feel like a blind man, now... ;)
ProgramFOX at 28-Jun-13 12:27pm
   
:laugh:
+5, if I could!
Maciej Los at 28-Jun-13 12:36pm
   
;)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have a look at similar questions and answers:
split data into 2 gridview tables[^]
How do I split a table over 2 pages?[^]
Split datatable into multiple tables[^]
 
I hope this is what you're looking for...
 

[EDIT #1]
This day was a rainy sunday, so i had a time for fun with SQL. This is what i had done:
CREATE TABLE #tmp (MIVID INT, Quantity INT, [Value] INT)
 
INSERT INTO #tmp (MIVID, Quantity, [Value])
SELECT 1 AS MIVID, 10 AS Quantity, 3000 AS [Value]
UNION ALL SELECT 1, 20, 3500
UNION ALL SELECT 1, 15, 2000
UNION ALL SELECT 2, 20, 3000
UNION ALL SELECT 2, 50, 7500
UNION ALL SELECT 3, 25, 2000
 
--declare temporary table (variable)
DECLARE @commands TABLE (ID INT, command VARCHAR(MAX))
 
--insert data
INSERT INTO @commands (ID, command)
SELECT DISTINCT MIVID AS ID, 'SELECT * FROM #tmp WHERE MIVID = ' + CONVERT(VARCHAR(10),MIVID) AS command
FROM #tmp
 
--declare variable to store command to execute
DECLARE @sql VARCHAR(255)
 
--declare cursor to go through the temporary table to execute command
DECLARE sql_cursor CURSOR
	FOR SELECT command FROM @commands
OPEN sql_cursor
FETCH NEXT FROM sql_cursor INTO @sql;
 
WHILE @@FETCH_STATUS=0
BEGIN
	PRINT @sql		
	EXEC(@sql)
	FETCH NEXT FROM sql_cursor INTO @sql;
END
 
CLOSE sql_cursor
DEALLOCATE sql_cursor
 
DROP TABLE #tmp
Result: 3 data-sets - exactly as you expect Wink | ;)
  Permalink  
v2
Comments
Espen Harlinn at 30-Jun-13 17:46pm
   
Well answered :-D
Maciej Los at 30-Jun-13 17:53pm
   
Thank you, Espen ;)

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 30 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100