Where would I declare variables in SQL Server 2008
Posted on 2012-04-13
I am up-scaling my database to SQL from Access. As I am converting many of the Queries to TSQL I am also looking at ways to make thing easier to maintain.
There are several variables that I would like to be available to me in queries and views, they really are very few and very simple. I would Like to simply store some exchange rates and also some tax rates.
So in my query I would be able to write something along the lines of
CAST(SUM(dbo.Products.[STG-R] * @TAXRATE) AS decimal(10 , 2))
CAST(SUM(dbo.Products.[STG-R] * 1.2) AS decimal(10 , 2))
I am confused as to where the best place to store something like this and how to declare it. Would it go in a stored procedure? Would it then be automatically available to all of my queries or would I need declare it at the beginning of the query.
Would appreciate any help you can offer. Many thanks.