Author |
Topic |
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-09 : 12:12:24
|
Hi,Can anyone tell me how I can add values of a column without using any functions? I know I can do that with Sum.but if I don't want to use it?thanksp.s. I'm new to SQL!! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-09 : 12:15:32
|
Not sure what you mean? do you mean adding all the values of column in a table? or add based on some grouping?can you illustrate your scenario please? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-09 : 12:18:51
|
if question was just to add up the values of column without any grouping applied and without use of SUM() function you can do it like thisDECLARE @ColSum intSELECT @ColSum=COALESCE(@ColSum,0)+YourColumnFROM YourTableSELECT @ColSum--this will give your sum |
|
|
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-09 : 13:12:36
|
visakh16,it's you again :)I'm not allowed to use any functions. so can't use the SUM function for example!the question says: the salary total without using any functions (i.e. Sum or others...)He has given us a table called employee with their names, salaries, etc. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-09 : 13:18:32
|
[code]DECLARE @SalaryTotal Numeric(12,2)SELECT @SalaryTotal=COALESCE(@SalaryTotal,0)+salaryFROM employeeSELECT @SalaryTotal--this will give your sum[/code] |
|
|
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-09 : 19:01:15
|
what does the @ sign do? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-09 : 23:00:15
|
quote: Originally posted by tennis_girl what does the @ sign do?
@ sign indicates its a local variable in SQL Server. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-10 : 00:59:07
|
quote: Originally posted by tennis_girl visakh16,it's you again :)I'm not allowed to use any functions. so can't use the SUM function for example!the question says: the salary total without using any functions (i.e. Sum or others...)He has given us a table called employee with their names, salaries, etc.
Why is the use of SUM not allowed?MadhivananFailing to plan is Planning to fail |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 01:09:56
|
quote: Originally posted by madhivanan
quote: Originally posted by tennis_girl visakh16,it's you again :)I'm not allowed to use any functions. so can't use the SUM function for example!the question says: the salary total without using any functions (i.e. Sum or others...)He has given us a table called employee with their names, salaries, etc.
Why is the use of SUM not allowed?MadhivananFailing to plan is Planning to fail
May be teacher hasnt taught aggregation functions chapter yet |
|
|
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-10 : 04:12:09
|
The prof kinda sucks, so I'm just searching the commands on line.He asked us to do it 2 ways, using a function and not using a function. that's the point of the excercise kinda! |
|
|
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-10 : 04:14:27
|
quote: Originally posted by visakh16
quote: Originally posted by tennis_girl what does the @ sign do?
@ sign indicates its a local variable in SQL Server.
We're using PostgreSQL (on linux!! grrr) for the time being and never seen using the @ sign.I guess I'll skip that for now :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 04:17:12
|
for postgreSQL specific solutions post in postgresql forums like www.dbforums.com. This is MS SQL Server forum so solutions here will be as per SQL Server syntax. |
|
|
tennis_girl
Starting Member
40 Posts |
Posted - 2008-11-10 : 05:29:13
|
Visakh16, thanks for the tip.I downloaded MS SQL server on my laptop to practice, remember? :)so I make sure to ask specific qs here. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-10 : 05:37:53
|
Ok...Just told to indicate that solns provided will not always work fine in PostGre |
|
|
|