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

Stored Procedure looks at sysobjects and process info in each table

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
Take all of those names and use them as the table name in the SELECT command
Process each table individually.

I also need to be able to either output a view or have the stored procedure output all the rows that it has processed.

I've done some reading on using cursor and I think thats the way I want to go but I'm really not sure where to go. If anyone has any ideas on how to do this or could just point me in the right direction, it would be greatly appreciated.

Thanks.
Nov 30 '06 #1
5 4097
aaryan
82
hi zseifts

declare @name varchar(20)
declare sampcursor1 cursor for select name from sysobjects where type = 'U' and sysstat <> 8275
open sampcursor1
fetch next from sampcursor1 into @name
while @@fetch_status = 0
begin
declare @sql varchar(8000),@from varchar(10)
set @from = @name
select @sql = 'select * from ' + @from
exec(@sql)
fetch next from sampcursor1 into @name
end
close sampcursor1
deallocate sampcursor1
go

hope this will help u to proceed further
Dec 1 '06 #2
iburyak
1,017 Expert 512MB
You did a grate job for a novice.

Your variable name @from is 10 characters long and @name is 20 it cuts names and system doesn't recognize tables.

1. Make them equal @from varchar(20)
2. You don't need @from at all you can use @name instead.
3. Check if you have tables with longer names than 20 in sysobjects and be generous declare @name varchar(100).... :)


Good luck.
Dec 1 '06 #3
Thanks aaryan and iburyak, I'm going try this when I get my test sql server up.
Dec 1 '06 #4
Okay, So I've tried to get that SP working that was posted earlier, but its not working. I can get it to loop through once then it would return the info from the first table and none other ones. Anyone have any ideas?

-Zach
Dec 4 '06 #5
iburyak
1,017 Expert 512MB
How do you get the data?
If you run through something like SQL Query analyzer you should be able to see everything.
If through some front end like VB you should request next recordset in a loop to be able to see more.

Did you change size of @from varchar(10) to @from varchar(20).
Run
select name from sysobjects where type = 'U' and sysstat <> 8275
and see how many records you should have in return.
Dec 4 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: aaapaul | last post by:
Hallo ! I have a Table with a column "ordernumber" ordernumber A12 A45 A77 A88
4
by: deprins | last post by:
Hello, I have wrote a stored procedure but its real slow. Its activated by a button on web page but its takes to long to process and the web server gives a timeout message after 5 minutes. Is...
5
by: Lauren Quantrell | last post by:
Just wondering if this is good form: Alter Procedure "mySPName" @UniqueID int AS set nocount on set xact_abort off DELETE FROM tblNameOne
17
by: serge | last post by:
How can i delete all user stored procedures and all table triggers very fast in a single database? Thank you
0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
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...
2
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create, read, update, delete data in a SQL Server 2000 data...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
4
by: gamaz | last post by:
Hi, I am trying to work on a stored procedure that will work with multiple database. I have a prototype of multiple databases. Those are named as the following: ts2_aldkm_app, ts2_aldkp_app,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.