2
I have a query that returns the following data:
SELECT * FROM METAS
mes lj saldo meta
4 2 153:59 123:00:00
4 2 25:33 00:00:00
4 2 29:57 08:00
4 2 38:58 45:00:00
4 2 94:47 20:00
4 2 23:41 15:00:00
4 2 215:37 70:00:00
4 2 213:41 120:00:00
4 2 235:38 80:00:00
4 2 36:13 13:00:00
But I need it done that way:
SELECT
mes,
lj,
SUM(saldo) as salto_total,
SUM(meta) as meta_total
FROM METAS
It returns me the following error:
Message 8117, Level 16, Status 1, Line 1 Operand data type varchar is invalid for sum Operator.
The reason is that my balance and goal fields are varchar format.
I’ll get that one tip
But it returns the following error:
Message 245, Level 16, Status 1, Line 1 Conversion failed when Converting the varchar value '00:00' to data type int.
How could I make that calculation ?
when the goal is
08:00
, the correct would be00:08:00
né (HH:mm:ss) ?! you have a serious problem storing this data. A simple numeric field or integer would solve the problem– Rovann Linhalis
and the balance...
213:41
would be213:41:00
since in the middle it does not have 3 decimal places (HH:mm) ?– Rovann Linhalis
@Rovannlinhalis Expected results are : goal:1068:04:00 Balance: 494:00:00
– Chefe Druida
look at the trouble it is to normalize these data as @Josediz posted... I would think about redoing these columns soon...
– Rovann Linhalis
For accumulation of hours that exceed 24h the suggestion is the use of numerical column, using minutes as a unit. In this way, any calculation is simple and converting to hhh:mm is also simple.
– José Diz
I understand and agree with you , but these data that comes from another endeavour where I can not manipulate the structure of the database, I can consult, more I can not change
– Chefe Druida