July 1, 2026 at 12:00 am
Comments posted to this topic are about the item Getting the Average
July 1, 2026 at 1:35 pm
I'm not sure, but it seems that using the TRY_PARSE function does nothing more than slow down the query. Wouldn't Steve have the same result without that function?
July 1, 2026 at 4:34 pm
do you?
July 1, 2026 at 4:59 pm
Fine, make me actually test something out before commenting. Inconceivable!
I learned today that by removing the TRY_PARSE function and only having 'Steve' records I got this error:
Msg 8117, Level 16, State 1, Line 16
Operand data type varchar is invalid for avg operator.
The TRY_PARSE function helps with type casting for the AVG function.
July 1, 2026 at 8:02 pm
Lol. I knew there was an error, but I had to re-test too 😉
July 2, 2026 at 8:04 am
declare @t table(id int identity, i int)
insert @t select null
insert @t select 11
select avg(try_parse(i as int)) from @t group by id
Argument data type int is invalid for argument 1 of parse function.
July 2, 2026 at 4:01 pm
You've incorrectly tested this. The question stores data as strings.
try_parse isn't for numerics

July 16, 2026 at 3:53 pm
As a follow up, Larry, I'll add a new row. Notice the value is the same for avg.

Is it slower, perhaps. But what about this?

Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply