Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 use parameter to sum column

Author  Topic 

pamyral_279
Posting Yak Master

143 Posts

Posted - 2012-02-06 : 21:48:28
Hi all,

I have table with Field (ID,Mark1,Mark2 with int field, StoreDate with Date)
ID Mark1 Mark2 StoreDate
Now, i want to create procedure with parameter Mark in order to sum Mark1 and Mark2 field. I do :
Create Procedure SumMark
@Mark
as
select Sum(@Mark) from table1
mean that when i use : Sum(Mark1) and Sum(Mark2)
But i found error : Must declare the scalar variable "@Mark".
Any one help correct it !

Thank you very much.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-06 : 23:23:47
[code]
Create Procedure SumMark
(@Mark char(5))
as
if @mark = 'mark1'
select Sum(Mark1) from table1
if @mark = 'mark2'
select sum(mark2) from table1
[/code]


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

pamyral_279
Posting Yak Master

143 Posts

Posted - 2012-02-07 : 01:10:51
Good idea ! have you other solutions in case i have many field mark1,mark2,mark3 ...
Thank you very much !
Go to Top of Page
   

- Advertisement -