How do sql variables work?
I have a table with salary of multiple employees in a table. and i need to calculate zscore for these emplyees using a derived number (mean and stddevn), i know i can do this in the select statement. but if i wanted to use variables. i am new to sql and just trying out things here. please bare me if my question is stupid declare @Weight int, @weight2 int, @Mean int, @StdDevn int, @Variance int set @Weight = 30 set @weight2 = (POWER(@weight,2)/100) select @Mean = AVG(salary) FROM [live].[dbo].[ProdKey] select @StdDevn = STDEV(salary) FROM [live].[dbo].[ProdKey] select @Variance = (POWER(@StdDevn,2)/100) select * FROM [live].[dbo].[ProdKey], (([salary]-@Mean)/@StdDevn) as Zscore Error desc - Must declare variable @Mean, Incorrect syntax near '-'