15,847,263 members
See more:
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
Updated 28-Jun-13 21:28pm
v3
Maciej Los 28-Jun-13 12:19pm
What you mean "how to split table in to mulitple tables"?
ASP.NET? WinForms?
Thomas Daniels 28-Jun-13 12:22pm
ASP.NET (see subject: Table splitting in asp.net)
Maciej Los 28-Jun-13 12:26pm
I feel like a blind man, now... ;)
Thomas Daniels 28-Jun-13 12:27pm
:laugh:
+5, if I could!
Maciej Los 28-Jun-13 12:36pm
;)

## 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:
SQL
```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 ;)

v2
Espen Harlinn 30-Jun-13 17:46pm