Home All Groups Group Topic Archive Search About
Author
13 Jan 2006 3:51 PM
Greg Smith
Is it possible to pass a table name to a stored procedure?

I have a ton of stored procedures that do the same basic thing, just on
different tables.

Can I pass a table name, and, if so can you give me an example?


Ant help is greatly appreciated.

Author
13 Jan 2006 3:56 PM
Ryan
This can be acheived with Dynamic SQL. There are pros and cons of this
approach...

http://www.sommarskog.se/dynamic_sql.html



--
HTH. Ryan
Show quote
"Greg Smith" <g**@umn.edu> wrote in message
news:ug6TLmFGGHA.3000@TK2MSFTNGP14.phx.gbl...
> Is it possible to pass a table name to a stored procedure?
>
> I have a ton of stored procedures that do the same basic thing, just on
> different tables.
>
> Can I pass a table name, and, if so can you give me an example?
>
>
> Ant help is greatly appreciated.
>
Author
13 Jan 2006 4:00 PM
Aaron Bertrand [SQL Server MVP]
Please read:
http://www.sommarskog.se/dynamic_sql.html



Show quote
"Greg Smith" <g**@umn.edu> wrote in message
news:ug6TLmFGGHA.3000@TK2MSFTNGP14.phx.gbl...
> Is it possible to pass a table name to a stored procedure?
>
> I have a ton of stored procedures that do the same basic thing, just on
> different tables.
>
> Can I pass a table name, and, if so can you give me an example?
>
>
> Ant help is greatly appreciated.
>
Author
13 Jan 2006 5:12 PM
Erland Sommarskog
Greg Smith (g**@umn.edu) writes:
> Is it possible to pass a table name to a stored procedure?
>
> I have a ton of stored procedures that do the same basic thing, just on
> different tables.
>
> Can I pass a table name, and, if so can you give me an example?

Can. But probably shouldn't do.

When you are in this situation, there are two likely causes:

1) Someone split up one table into may, so you have Sales04, Sales05 etc.
   Bad. But build a view over them, and access the view instead.

2) The tables are lookup tables, that indeed has a similar structure,
   but describe apart entities. Each table should then have its own
   procedure. They may be similar today - but tomorrow it may be different.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
17 Jan 2006 4:05 AM
--CELKO--
Think about this.  What would call such a procedure?   The Britney
Spears, automobiles, squid or anything in the Entire Universe
procedure?

>> I have a ton of stored procedures that do the same basic thing, just on different tables. <<

So what?  Have you ever had a basic Software Engineering course in
College?  If not, you are not going to learn the basics on a Newsgroup.


If you really do not care about Software Engineering, software quaity,
etc. you can kludge this with some crappy dynamic code.

Read what Erland wrote as a source for possible problems in the schema.
Author
17 Jan 2006 11:13 AM
Tony Rogerson
I read your post that you advocate using many stored procedures when in we
could actually normalise this into a single more maintainable stored
procedure.

We don't get paid by lines of code anymore, we get paid for a timely result,
supportability and performance.

The only kludge here is your in ability to get your head round real world
problems and techniques - get out of the class room and wake up!

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials


Show quote
"--CELKO--" <jcelko***@earthlink.net> wrote in message
news:1137470750.548127.166350@g49g2000cwa.googlegroups.com...
> Think about this.  What would call such a procedure?   The Britney
> Spears, automobiles, squid or anything in the Entire Universe
> procedure?
>
>>> I have a ton of stored procedures that do the same basic thing, just on
>>> different tables. <<
>
> So what?  Have you ever had a basic Software Engineering course in
> College?  If not, you are not going to learn the basics on a Newsgroup.
>
>
> If you really do not care about Software Engineering, software quaity,
> etc. you can kludge this with some crappy dynamic code.
>
> Read what Erland wrote as a source for possible problems in the schema.
>

AddThis Social Bookmark Button