473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating a stored procedure

Jim
Im trying to create a stored procedure that selects everything from a
function name that im passing in through a parameter..

create procedure SP_selectall
(@functionname varchar(25))
as

select * from @functioname

go

I keep getting this error:

Server: Msg 137, Level 15, State 2, Procedure SP_selectall, Line 5
Must declare the variable '@functioname'.

Whats the issue?
Jul 20 '05 #1
1 4158

"Jim" <ji********@motorola.com> wrote in message
news:72*************************@posting.google.co m...
Im trying to create a stored procedure that selects everything from a
function name that im passing in through a parameter..

create procedure SP_selectall
(@functionname varchar(25))
as

select * from @functioname

go

I keep getting this error:

Server: Msg 137, Level 15, State 2, Procedure SP_selectall, Line 5
Must declare the variable '@functioname'.

Whats the issue?


You could do this with dynamic SQL (see below), but that's probably not a
good idea. What happens if some functions require parameters and some don't?
If you don't know the function name ahead of time, then you don't know the
form of the result set, so you may have difficulties handling it on the
client side. Performance could be a problem too, if any of the functions are
complex. For a detailed discussion of dynamic SQL, see here:

http://www.algonet.se/~sommar/dynamic_sql.html

But having said all that, if you have a good reason, and if you're
completely sure that you will never write a function requiring parameters,
then this should work:

create proc dbo.SelectAllFromFunction
@FunctionName sysname
as
set nocount on
begin
exec('select * from dbo.' + @FunctionName + '()')
end

This is for table-valued functions only, of course. You shouldn't use sp_ as
the prefix for your stored procs, by the way - that's used for system procs,
and the name resolution is different for them.

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
0
by: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone....
1
by: Paul | last post by:
Hi, I wish to be able to add tables to a sql server database at runtime from my asp.net application. As well as creating fields I also wish to be able to create indexes on selected fields and to...
4
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: ...
1
by: Ir0neagle | last post by:
I am generating upgrade/new install scripts for my project. I am able to do this in oracle and sql server but an running into problems in db2. What I am trying to do is to use some logic to only...
9
by: jyothi1105 | last post by:
Hi all, Here is some information which could help people who want to create stored procedures and execute them in their program. You can create stored procedures in two ways: Through front end...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
0
by: mersis | last post by:
I have a very very annoying problem. I want to create a stored procedure, that creates a table and does various things with it. Before creating a stored procedure I check if the table is there. If it...
1
by: apothecary | last post by:
Hello Newbie here. Is there a way of creating a VIEW...using a stored procedure. I am basically trying to create a view to return some data that I am getting using a stored procedure. I...
1
by: Quish | last post by:
Hey I am creating a database application that is accessed through a .NET front end. What I want to do is run a SQL script that will create my DB, create my indexes and enforce my constraints...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.