Skip to content
Advertisement

can you set environmental variable to round numbers in SQL Server query?

I have a bunch of calculations in a SQL Server 2012 query, kind of like:

I used a round function here, but I need to add a lot more similar lines. Is there any way to just set a global variable to round all columns in one shot? Otherwise it’s just a lot of leg work.

I’ll be pasting to Excel but it would be nice to round it in the source without having to use the round function so many times.

Advertisement

Answer

Here is a workaround, no need to type Round() function for every line:

Edit:

If you cannot use temp table, you can wrap your query with CTE then just Round() the result of CTE, which is pretty easy to do with help of a multiline editor like Sublime Text or VisualStudio Code:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement