summation of fields | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

summation of fields

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
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
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!
]]>