I have an SQL statement which selects various data from a table in my database and I have declared variables within my code like:
DECLARE @TotalAge int;
Let's say one of the fields in the table is Age
, how would I sum the collected values from the query and assign them to the variable as a total?
First set @TotalAge
:
set @TotalAge=(select sum(Age) from TableName)
then select @TotalAge
where you want:
select @TotalAge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With