SQL Server Performance

summation of fields

Discussion in 'T-SQL Performance Tuning for Developers' started by Dominic29, Nov 10, 2004.

  1. Dominic29 New Member

    Hi,

    I'm building an application in VB using DataEnvironment, DataReport and a SQL Server database. I've created a Stored Proc with the following query:

    SELECT tcqDatetime, tcqFinitionFM, tcqCriticalSplit, tcqCriticalGashed,
    tcqCriticalCrumbled, tcqVisualHunchback, tcqVisualFrizzy,
    tcqGeomThick, tcqGeomThin, tcqGeomVeiled,
    tcqGeomElbow, tcqGeomLong, tcqGeomCourt,
    tcqGeomWide, tcqGeomNarrow, tcqGeomCanot,
    tcqGeomNeedle, tcqGeomNode, tcqPrintLight,
    tcqPrintDark, tcqPrintWrong, tcqDefectsInEnds,
    tcqTensionOfRibbons, tcqSpattersOfGlue,
    FROM dbo.TB_pcqPalletControlQuality
    WHERE (dbo.TB_palPallet.palCode = @Pallet)

    What I need to do is the query to return a summation of fields of the same "category": like "tcqCriticalSplit + tcqCriticalGashed + tcqCriticalCrumbled", "tcqGeom... + tcqGeom... + tcqGeom...", like subtotals. I need the query to do it, because I need to print these informations on the DataReport. Example:

    Split Gashed Crumbled TOT Thick Thin Veiled ... TOT
    1 2 1 4 2 1 1 (total of geom fields).

    Is there a way to do it?

    thanks a lot for your time and help
  2. Twan New Member

    do you mean...


    SELECTtcqDatetime,
    tcqFinitionFM,
    tcqCriticalSplit,
    tcqCriticalGashed,
    tcqCriticalCrumbled,
    tcqCriticalTotal = tcqCriticalSplit + tcqCriticalGashed + tcqCriticalCrumbled,
    tcqVisualHunchback,
    tcqVisualFrizzy,
    tcqGeomThick,
    tcqGeomThin,
    tcqGeomVeiled,
    tcqGeomElbow,
    tcqGeomLong,
    tcqGeomCourt,
    tcqGeomWide,
    tcqGeomNarrow,
    tcqGeomCanot,
    tcqGeomNeedle,
    tcqGeomNode,
    tcqGeomTotal = tcqGeomThick + tcqGeomThin + tcqGeomVeiled + tcqGeomElbow + tcqGeomLong +
    tcqGeomCourt + tcqGeomWide + tcqGeomNarrow + tcqGeomCanot + tcqGeomNeedle + tcqGeomNode,

    tcqPrintLight,
    tcqPrintDark,
    tcqPrintWrong,
    tcqDefectsInEnds,
    tcqTensionOfRibbons,
    tcqSpattersOfGlue,
    FROM dbo.TB_pcqPalletControlQuality
    WHERE (dbo.TB_palPallet.palCode = @Pallet)
    Cheers
    Twan
  3. Dominic29 New Member

    Yhea, that's exactly what I meaned! I didn't knew we could do this kind of operation in a SQL statement. thanks a lot for your help!

Share This Page