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

how to write one stored procedure for a (same column )present in 20 tables

hi,
i am a learner of ms -sql server 2000, i had a doubt in stored
procedures

suppose i have a data base having 20 tables, all the tables have a
column named--DATE

can we write a store procdure to find out the data ---i mean i want
the data entered
between two days ---- if i call the stored procedure in any one of the
table i need to get the answer

pls help me how to write the stored procedure

satishkumar.g

Mar 8 '06 #1
2 1689
MC
Do you mean calling the procedure for any one table and then getting the
data from the table with a date filter? If yes, then you would need to use
dynamic string and send the table name and two dates to the stored procedure
as parameters. Something like

create procedure dbo.GetData
(
@tablename varchar(100),
@dateFrom datetime,
@dateTo datetime
)

as

execute
('
select * from '+@tablename +' where date >= ' + @dateFrom +' and date <= '+
@dateTo
)

go

offcourse, you should check the part with dates and see what would you
actually want to get back. Do you want to filter by time, should it include
or exclude datefrom data in the results and so on. You should also consider
using sp_executesql instead of execute.

MC

"satish" <sa**********************@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
hi,
i am a learner of ms -sql server 2000, i had a doubt in stored
procedures

suppose i have a data base having 20 tables, all the tables have a
column named--DATE

can we write a store procdure to find out the data ---i mean i want
the data entered
between two days ---- if i call the stored procedure in any one of the
table i need to get the answer

pls help me how to write the stored procedure

satishkumar.g

Mar 8 '06 #2
MC's answer is awesome IMO.

Only thing I might add is that this is called "Dynamic SQL."

For sure has its uses. Erland has some excellent writeups regarding how
easy it is to overuse this technique.

Obvious questions come up such as "Why do you have 20 tables all with
the same data?"

Mar 8 '06 #3

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

Similar topics

3
by: gwaddell | last post by:
I have an Access XP ADE application connected to a SQL Server 7.0 SP4 database. I have created a timestamp column in the main table. Unfortunately, I am now getting persistent write conflict...
1
by: Steen Andreassen | last post by:
Hi Group... In one of my tables in a SQL-2000 db, do I have a calculated column calling a user defined function. That's not a problem, but now I need to update another column in the same...
4
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
5
by: Bari Allen | last post by:
I'm trying to test for concurrency, using a SQL Stored Procedure on a RowVersion (timestamp) Field. The vb code I'm using is as follows Dim cmd As New SqlCommand("ConcurrencyCheck", cn) Dim...
2
by: Joe Campbell | last post by:
I have a DBA that wrote a stored procedure that does a SELECT from a particluar SQL Server table. Within that stored procedure he links over to grab a column from another database table. I need to...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
0
by: =?Utf-8?B?X3ByZWZpeA==?= | last post by:
Hello All, I have written a page with a sqlserverdatasource control and a formview web control. I want to use stored procedures to perform CRUD operations. Formview textboxes bind to table...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.