Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sp error

Status
Not open for further replies.

mtl77

Programmer
May 27, 2003
31
CA
Hi all,

I have created the sp below and for some reason it will not allow me to create the SP because it says that i have a syntax error near @UsedToCal.

I am relatively new at stored procedures and i can't seem to figure out why this is happening, any ideas?

The code is as follows:

Create Procedure......
@PersonID int,
@UsedToCal int,
@OldestDate DateTime,
@Average decimal output

AS

SELECT @Average = avg(HD) FROM (SELECT TOP @UsedToCal HD FROM Mytable Where PersonID = @PersonID and Date>= @OldestDate) B

GO

thanks in advance for any help.

mtl77
 
declare @sql_command varchar(400)

sey @sql_command =

'SELECT @Average = avg(HD) FROM (SELECT TOP ' + @UsedToCal + 'HD FROM Mytable Where PersonID = ' + @PersonID + ' and Date>= ' + @OldestDate + ') B'


Thanks

J. Kusch
 
Sorry ... after that you need to add the following ...

exec (@sql_command)

Thanks

J. Kusch
 
And this line

sey @sql_command =

should be

set @sql_command =

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top