1. Merge Cells
--- http://stackoverflow.com/questions/21512260/merge-equal-table-cells-with-jquery
--- function MergeGridCells()
2. Code PHP (Line 1 - 20) == SQL Query
Code (SQL)
SET NOCOUNT ON;
DECLARE @tmp_TableA TABLE (grpName varchar(10),
grpValue varchar(10),
grpID int,
rowID int)
INSERT INTO @tmp_TableA
SELECT 'aa', 'value1', 1, 1 UNION
SELECT 'aa', 'value2', 1, 2 UNION
SELECT 'bb', 'value1', 2, 3 UNION
SELECT 'bb', 'value2', 2, 4 UNION
SELECT 'cc', 'value1', 3, 7 UNION
SELECT 'cc', 'value2', 3, 9
DECLARE @cnt int = 1;
DECLARE @max int = (SELECT MAX(rowID) FROM @tmp_TableA);
DECLARE @grpIDOld int = 0
DECLARE @grpIDNew int = 0
DECLARE @grpName varchar(10) = ''
WHILE (@cnt <= @max) BEGIN
SELECT @grpName = GrpName, @grpIDNew = GrpID FROM @tmp_TABLEA WHERE rowID = @cnt
IF @@ROWCOUNT > 0 BEGIN
IF @grpIDOld <> @grpIDNew BEGIN
SET @grpIDOld = @grpIDNew
END
ELSE BEGIN
UPDATE @tmp_TABLEA SET GrpName = '' WHERE rowID = @cnt
END
END
ELSE BEGIN
PRINT CAST(@cnt AS VARCHAR) + N' เปลียนกลุ่ม'
END
SET @cnt = @cnt + 1
END
SELECT * FROM @tmp_TAbleA