• Hi Jeff,

    Thanks for the quick answer !

    I have several questions regarding your message, also maybe because I forgot to say that I'm quite a newbie to this whole SQL Server thing.

    First, why do you say my table has a denormalized structure ?

    Then, regarding the clustered index and the PK, you are right I could have avoided the use of an ID column because each row can be find by a unique combinaison of YPID, CellX, CellY and CellZ. I used an ID only for easier reference as foreign key on one other table but I can easily use 4 columns in this other table instead of the current cell ID.

    In fact, when I created the rows for this ConfigCell table I have generated the ID column based on these 4 others with something like CellX + 1000* CellY + 100000 * CellZ + 10000000 * YPID.

    So, to sum up, would you recommend to

    1) drop the ID column ?

    2) set the PK (clustered index) on YPID, CellX, CellY and CellZ ?

    And finally to answer your question about the divide by 1, it's true it this case it is not relevant but these are dynamic values and in this special case the value was 1.

    The VB.NET code used to generate the SELECT query is the following :

    sqlCommand = String.Format(

    "SELECT AVG([{1}]) AS {1}, AVG([{2}]) AS {2}, AVG([{3}]) AS {3}, AVG([{4}]) AS {4} " &

    "FROM [{0}] " &

    "WHERE [{1}] BETWEEN {5} AND {6} AND " &

    "[{3}] >= {7} AND [{3}] < {8} AND " &

    "[{9}] = {10} " &

    "GROUP BY ((([{1}] - {5})/{11}) + {5}), ([{2}]/{12}) " &

    "ORDER BY [{1}], [{2}], [{3}]",

    tConfigCell.TableName,

    tConfigCell.Fields.CellX.ToString, tConfigCell.Fields.CellY.ToString, tConfigCell.Fields.CellZ.ToString, qltField,

    subpile.CellDMin.CellX, subpile.CellDMax.CellX,

    CInt(layer.LowPos.Value), CInt(layer.HeighPos.Value),

    tConfigCell.Fields.YPID.ToString, tDBTable.PrepareStringForSQL(subpile.Parent.ID),

    grid.X, grid.Y)

    The values {11} and {12} used as divisor in the GROUP BY are the grid.X and grid.Y. Because I can choose custom "grid" (1x1, 3x3, 5x5, ...) to display on the graphs.

    The value {5} used in the GROUP BY ((((CellX - 1)/1) + 1) is the min value for the CellX (also used as the first argument in the BETWEEN) here again in this example it was 1 but on diffrent YardPart (YPID) it could be something else.

    Joël