question

sqlnovice avatar image
sqlnovice asked

what is (select avg(Quantity) * .1 equal to?

need some help on this
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
By itself, it's just a syntax error :) "*" is the multiplication operator in SQL Server so, when it's part of a full query, your snippet gives you 10% of the average Quantity. Here are a couple queries to demonstrate the different outcomes you would see when using "*.1" and not multiplying the average: USE tempdb SELECT AVG(column_id) FROM sys.columns SELECT AVG(column_id) * .1 FROM sys.columns
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Note also that, due to the way SQL server handles that sort of query, you're likely to get a different result depending on where you do the multiplication: USE tempdb SELECT AVG(column_id * .1), AVG(column_ID) * .1 FROM sys.columns (I suspect. It's late, I'm tired, I could be wrong.)
1 Like 1 ·
Great point. Gotta love integer "rounding!"
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.