|
Hi all, I had a request to show total services being run etc. but am struggling with the output. What I want to see is What I am getting is For some reason it is adding an extra 2 services1, and only summing the full service column, instead of adding services1 + Minutes together... Any ideas would be greatly appreciated... Below is my sql the adding columns bit doesn't seem to work...
(comments are locked)
|
|
The problem was how I was referencing columns in my select statement. I wasn't doing calculations on (CONVERT(INT,(SUM((Services1) + (Services2)))) AS FullService when what I should have done was
Anyone reading this remember the order of how SQL constructs it's queries! What I could understand from snippet is that you may use isnull instead of coalesce function
Feb 13 '12 at 04:53 PM
inder
(comments are locked)
|
|
If you do not let us know the details, how could you expect a perfect answer? But seems like you need to change the to
(comments are locked)
|
|
You changed the question after I posted by comment above, so here is the answer now with the column defined properly: Just as @robbin wrote, run the SUM() around the addition and you get the expected output. I found the problem... it was a problem with my subqueries... Doh! Thanks for your help though!
Feb 13 '12 at 04:36 PM
jhowe
(comments are locked)
|


Seems like it is not the full script you have posted? Is the information derived from only one table?
Going with the information you provided you already get what you expect:
I have no idea how you make the final column (FullService) as you are referencing other tables/columns not mentioned in your question. PLease provide a little more detail so we can help out further.
Test data, table definitions and expected result usually help us out the most.
it's the OUTPUT i'm concerned with as I only want to show one row instead of multiple rows... as mentioned earlier --(CONVERT(INT,((Services1) + (Minutes)))) AS FullService is not giving me the results I want. The columns are not adding together correctly and also if I include them in my query I have to add them into the group by which splits the rows out...
I haven't added tables etc. cause it's a fairly lengthy/complicated query and think that I will be able to resolve it once I figure out the full service calculation and stop the output from displaying multiple rows...