March 26, 2012 at 4:12 am
Hi There!
I have created a simple table with 3 fields "Con_Flag" , "ZL_Count" and "Total_Op_Atts".
"Con_Flag" has been created with a CASE Statement (populated with 1 OR 0).
I would like to populate "Con_Flag" with figures from table1
I would like to SUM on "ZL_Count" (as I will later be doing a calculation between "ZL_Count" and "Total_OP_Att's")
CREATE TABLE #ZL_Calculation1
(Con_Flag INT,
ZL_Count INT,
Total_Op_Atts INT)
INSERT #ZL_Calculation1
(Con_Flag,ZL_Count)
SELECT Con_Flag,
SUM (ZL_Count)
FROM [#ZL_TBL1]
GROUP BY Con_Flag
For some reason I get the above message. Not quite sure why; haven't I defined the column correctly?
Any help would be appreciated! 🙂
My desired outcome would be:
Con_Flag ZL_CountTotal_OP_ATT
0 500
1 3752
March 26, 2012 at 4:59 am
What is the table definition of #ZL_TBL1?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
March 26, 2012 at 6:06 am
assuming all the values are numeric, you should explicitly convert it to int inside the sum:
SUM (CONVERT(int,ZL_Count))
alternatively, the better solution is to make sure your destination table has that column defined as integer, instead of however it gets created now.
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply