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
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 SP parameter passing

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2009-05-06 : 10:40:11
I have a proc like below,
CREATE PROC foo @dbnm  varchar(100) = null
AS SELECT @dbnm
go


When I try to execute as below it fails,
EXECUTE foo db_name()
GO


where as the folloing aproach works,
DECLARE @v varchar(100)
SELECT @v = db_name()
EXECUTE foo @v

Is this how it supposed to work? Is there a way to achieve this in one EXECUTE statement?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-06 : 12:45:15
Yes that's how it is supposed to work. You can not do it in one statement.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2009-05-06 : 12:50:26
Thank you, Tara.

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-06 : 12:56:10
You're welcome.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -