473,395 Members | 1,941 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,395 software developers and data experts.

How to pass table names to a Stored procedure

adi
Hi all,
Seems like a fundamental question to me but I dont have a definite
answer for it, Gurus please enlighten me.

I have a table 'Table1' whose structure changes dynamically based on
some configuration values from another table. This table is being used
by a program, It was initially used by this program which ran as a
single task (executing at only a specific interval) but now the program
has to be run mutiple times some coinciding with each othe - which
meant that table structure will change as 2 programs are running
simultaneously... and therefore I have decided to use seperate table
names that each has a structure of its now.

I use this table name 'Table1' in about 10-15 stored procedures and
UDF's

to make the long story short: Since I will not know which table I will
be using in the program I want to pass the table name as an argument to
the SP and UDF's and then access this param in the
'select's/updates/inserts' - but this doesn't work unless I use Dynamic
SQL.

Is there any other way of passing table names as parameters and then
using then in the procs?

any ideas will be really helpful.
adi

Dec 16 '05 #1
5 13653
Hi

Dynamic SQL is your answer here.
http://www.sommarskog.se/dynamic_sql.html

Regards
--------------------------------
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland

IM: mi**@epprecht.net

MVP Program: http://www.microsoft.com/mvp

Blog: http://www.msmvps.com/epprecht/

"adi" <Ad*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all,
Seems like a fundamental question to me but I dont have a definite
answer for it, Gurus please enlighten me.

I have a table 'Table1' whose structure changes dynamically based on
some configuration values from another table. This table is being used
by a program, It was initially used by this program which ran as a
single task (executing at only a specific interval) but now the program
has to be run mutiple times some coinciding with each othe - which
meant that table structure will change as 2 programs are running
simultaneously... and therefore I have decided to use seperate table
names that each has a structure of its now.

I use this table name 'Table1' in about 10-15 stored procedures and
UDF's

to make the long story short: Since I will not know which table I will
be using in the program I want to pass the table name as an argument to
the SP and UDF's and then access this param in the
'select's/updates/inserts' - but this doesn't work unless I use Dynamic
SQL.

Is there any other way of passing table names as parameters and then
using then in the procs?

any ideas will be really helpful.
adi

Dec 16 '05 #2
adi wrote:
I have a table 'Table1' whose structure changes dynamically based on
some configuration values from another table.

any ideas will be really helpful.
adi


Redesign the application. This is absurd.

Well you asked.
--
Daniel A. Morgan
http://www.psoug.org
da******@x.washington.edu
(replace x with u to respond)
Dec 16 '05 #3
adi wrote:
Hi all,
Seems like a fundamental question to me but I dont have a definite
answer for it, Gurus please enlighten me.

I have a table 'Table1' whose structure changes dynamically based on
some configuration values from another table. This table is being used
by a program, It was initially used by this program which ran as a
single task (executing at only a specific interval) but now the program
has to be run mutiple times some coinciding with each othe - which
meant that table structure will change as 2 programs are running
simultaneously... and therefore I have decided to use seperate table
names that each has a structure of its now.

I use this table name 'Table1' in about 10-15 stored procedures and
UDF's

to make the long story short: Since I will not know which table I will
be using in the program I want to pass the table name as an argument to
the SP and UDF's and then access this param in the
'select's/updates/inserts' - but this doesn't work unless I use Dynamic
SQL.

Is there any other way of passing table names as parameters and then
using then in the procs?

any ideas will be really helpful.
adi


I have to agree with Daniel. This sounds like a mess and not the way to
build any kind of scalable or reliable solution. Dynamic SQL may buy
you some time but I'd only go that route as a last resort and only as a
stop-gap for some better plan.

--
David Portas
SQL Server MVP
--

Dec 17 '05 #4
adi
Advice noted. I will re-design the app. Meanwhile can anyone of you
give me some nove ideas on how the whole thing can be scalable.
Frankly I am new to SQL Server and new to 'planning'

:-)

thanks
adi

Dec 20 '05 #5
adi wrote:
Advice noted. I will re-design the app. Meanwhile can anyone of you
give me some nove ideas on how the whole thing can be scalable.
Frankly I am new to SQL Server and new to 'planning'

:-)

thanks
adi


Did you read the article in the link that Mike posted? That answers
your original question.

What I'm saying is that any efforts to support such a design would be
better invested in replacing it. If you don't have anyone with
experience of database design then you should hire someone because I
think you'll need more help than you can get in a newsgroup. If you
have a more specific question then come back and give us some details.

--
David Portas
SQL Server MVP
--

Dec 21 '05 #6

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

Similar topics

0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
1
by: T.S.Negi | last post by:
Dear Techies, I making one stored procedure, which does some operation based on an interface hash (#) table ---- name #mydata. This stored has two section of code (seperated by parameter value...
2
by: jlficken | last post by:
I am trying to create a stored procedure that accepts 3 parameters. Using these parameters I am joining on 2 tables and a UDF that accepts these 3 parameters to get movement information. When I try...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1 below the call to that stored procedure does not...
3
by: Jim | last post by:
I have a stored procedure that queries a sql server database and returns the multiple data tables ( 7 to be precise) these tables are the results of many joins. When I use the...
0
by: Chan | last post by:
Hi, I am trying to send set of rows from my c# web service to Oracle stored procedure. I think I can get this done using OpenXML in SQL Server. How to implement this in Oracle Stored...
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
5
by: zseifts | last post by:
Hi everyone. I am fairly new to using stored procedures but for the past few days I've been reading up on them and I need to do the following: Get all the table names from the sysobjects table...
0
by: Afaque Khan | last post by:
HI All, I have a requirement, I need to pass table as IN parameter in the stored procedure. But when I do this it just says Table 'database.strtable' doesn't exist . Can you guys please advice...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.