Hi, i have to nest 2 cursors together and frankly i'm lost.
Here's what I have so far
CREATE PROCEDURE SeeAllColumns
AS
SET NOCOUNT ON
DECLARE @.strMessage VARCHAR(100)
DECLARE @.strColumn VARCHAR(100)
DECLARE @.strTable VARCHAR(100)
DECLARE @.strCommand VARCHAR(250)
SELECT @.strMessage = 'SELECT ALL TABLES'
PRINT @.strMessage
DECLARE crsTables CURSOR FOR
SELECT
name AS strTable
FROM
sysobjects
WHERE
name LIKE 'T%'
OPEN crsTables
FETCH NEXT FROM crsTables INTO @.strTable
WHILE (@.@.FETCH_STATUS = 0) BEGIN
SELECT @.strMessage = 'SELECT ALL COLUMNS'
PRINT @.strMessage
SELECT @.strCommand = ' SELECT ' + @.strColumn + ' FROM ' + @.strTable
EXECUTE (@.strCommand)
FETCH NEXT FROM crsTables INTO @.strTable
END
DEALLOCATE crsTables
PRINT 'DONE'
What i need to do is select all columns from all tables, but none of the actual data within the columns, just the names. I just don't know where or how to insert the 2nd cursor.
Can someone help me?
Thanks!Frankly ... you lost me somewhere in the middle of the proc ... could you plz explain what you are trying to do here ...
as far as it seems to me .. this proc will generate as many resultsets as the total no of columns in the database
DECLARE crsTables CURSOR FOR
SELECT
name AS strTable
FROM
sysobjects
WHERE
name LIKE 'T%'
should probably be
DECLARE crsTables CURSOR FOR
SELECT
name AS strTable
FROM
sysobjects
WHERE
xtype = 'U'
if you are trying to select all user tables|||declare @.tbl sysname
declare @.clm sysname
declare tbls cursor local fast_forward for
select [TABLE_NAME]
from [INFORMATION_SCHEMA].[TABLES]
where [TABLE_TYPE] = 'BASE TABLE'
open tbls
fetch next from tbls into @.tbl
while @.@.fetch_status = 0
begin
declare cols cursor local fast_forward for
select [COLUMN_NAME]
from [INFORMATION_SCHEMA].[COLUMNS]
where [TABLE_NAME] = @.tbl
open cols
fetch next from cols into @.clm
while @.@.fetch_status = 0
begin
print @.tbl + ':' + @.clm
fetch next from cols into @.clm
end
close cols
deallocate cols
fetch next from tbls into @.tbl
end
close tbls
deallocate tbls|||you can just get by with 1 cursor if you declare it against this statement (alternatively you can use information_schema.columns view):
select cast(object_name(id) as char(128)), colid, [name] from syscolumns
where objectproperty(id, 'istable')=1 and objectproperty(id, 'ismsshipped')=0
order by id, colid
Showing posts with label together. Show all posts
Showing posts with label together. Show all posts
Friday, March 23, 2012
Wednesday, March 21, 2012
Nested Tables
Using SSRS 2005, is there anyway to embed a table in a table and link the two together in a parent child relationship?
R
WHat do you want to achieve ? It sure can be accomplished by using the standard functionality.HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
Nested Sets Problem
I'm trying to see if this is possible. I have an employee table that
contains employee ID and manager ID. I'm trying to string together the
complete hierarchy for an employee in one row. So, if you have employee ID
1
reports to 2. Employee 2 reports to 3, then the result would be:
EmployeeID ReportingTo
1 2/3
Is this possible using nested sets? Can someone please give me some samples
of this?Have you searched google groups to see if there are solutions for similar
problems? If not look for "Joe Celko"+"nested sets".
Anith|||Susannah,
You should find a few useful things here:
http://groups.google.co.uk/groups? ...er+itzi
k
Steve Kass
Drew University
Susannah wrote:
>I'm trying to see if this is possible. I have an employee table that
>contains employee ID and manager ID. I'm trying to string together the
>complete hierarchy for an employee in one row. So, if you have employee ID
1
>reports to 2. Employee 2 reports to 3, then the result would be:
>EmployeeID ReportingTo
>1 2/3
>Is this possible using nested sets? Can someone please give me some sample
s
>of this?
>
contains employee ID and manager ID. I'm trying to string together the
complete hierarchy for an employee in one row. So, if you have employee ID
1
reports to 2. Employee 2 reports to 3, then the result would be:
EmployeeID ReportingTo
1 2/3
Is this possible using nested sets? Can someone please give me some samples
of this?Have you searched google groups to see if there are solutions for similar
problems? If not look for "Joe Celko"+"nested sets".
Anith|||Susannah,
You should find a few useful things here:
http://groups.google.co.uk/groups? ...er+itzi
k
Steve Kass
Drew University
Susannah wrote:
>I'm trying to see if this is possible. I have an employee table that
>contains employee ID and manager ID. I'm trying to string together the
>complete hierarchy for an employee in one row. So, if you have employee ID
1
>reports to 2. Employee 2 reports to 3, then the result would be:
>EmployeeID ReportingTo
>1 2/3
>Is this possible using nested sets? Can someone please give me some sample
s
>of this?
>
Subscribe to:
Posts (Atom)