473,396 Members | 1,785 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.

using sp_helpdb to get size of DB's. (Or another way???)

Thanks for you help in advance. I am trying to use sp_helpdb to get the size of all the databases on a sql server. The results of sp_helpdb (when using the @dbname='databasename') is 2 sets of data. The first iset s the results I want and the second set is the information about the files. While this second set of information is valid and relevant I don't want the second set for this query. So. Below is my code. You can see that I am parsing the sysdatabases table in the master db to create a temporary table so that I can use the @dataname variable later to feed to sp_helpdb. I can't figure out how to limit sp_helpdb and there might be a different way to do this. So I am asking for help.

FYI my Cursor works fine I just don't like the output with 2 result sets. So I would like to either figure out a different way to get DB size or reduce the result set of the sp_helpdb output.

START TSQL
************************************************** *****************************
DECLARE @fillfactor varchar(2)
DECLARE @tablename varchar(30)
DECLARE @tablename_header varchar(75)
DECLARE @dataname varchar(60)
DECLARE @dataname_header varchar(75)

DECLARE datanames_cursor CURSOR FOR SELECT name FROM sysdatabases
WHERE name like ('%SOMEVARIABLE%')

OPEN datanames_cursor
FETCH NEXT FROM datanames_cursor INTO @dataname

WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
SELECT @dataname = RTRIM(@dataname);
--PRINT @dataname
exec sp_helpdb @dbname=@dataname;
--FETCH NEXT FROM datanames_cursor INTO @dataname
CONTINUE
END


DEALLOCATE datanames_cursor
Oct 26 '07 #1
2 8812
I need to clarify this request. I have a script that works as a TSQL query that writes to a #tmp table. But I need to port this TSQL Script to SSRS and just copying the script to SSRS Report wizard does not work . I will post the code and the error. The error relates to using a TMP Table. ERROR: There is an error in the query. Invalid object name '#tmp'. I get this from the SSRS Design the query wizard. If I just enter the code and run it from inside visual studio sql server reporting tool it runs fine but I cant upload it to the SSRS Report Server.

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE TABLE #tmp
  3. (
  4. name varchar(200), 
  5. [size] varchar(20), 
  6. owner varchar(50), 
  7. dbid int, 
  8. created datetime, 
  9. status varchar(4000), 
  10. compat int
  11. INSERT INTO #tmp EXEC sp_helpdb
  12.                                                                                                                   SELECT      *
  13. FROM          #tmp
  14. WHERE      name LIKE '%searchstring%'
  15. ORDER BY size DESC 
  16.  
  17. DROP TABLE #tmp
  18.  
Oct 28 '07 #2
I found the answer.


Temp Tables Cause SSRS not to Populate Fields
Posted by Adam Rink at 7/19/2007 and is filed under SQL Server Reporting Services - SSRS
If you use stored procedures that contain dynamic SQL or temp tables, you know the frustration with SSRS not detecting the field names automatically for the report. The reason for this is because SSRS does not run the stored procedure to get the output and field names. Instead it uses the SET FMTONLY ON command to return just the metadata.

While sort of annoying when you have a few columns, when you have a ton it makes it a long and tedious task to build the report. The work around is to use text instead of a stored procedure type in your dataset. Then set the FMTONLY setting to off.

SET FMTONLY OFF;
EXEC dbo.mystoredproc

WARNING: This will execute the proc, so if you have some data modification code in the stored proc, then the data will be modified.
Oct 29 '07 #3

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

Similar topics

9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
0
by: Vanessa | last post by:
Hi I'm using crystal report v9.2 advanced and my development tool is VB.net under Win XP Professional. I'm trying to use the report to print to a printer with a defined custom size (continuous...
9
by: Dr. Know | last post by:
Greetings, I am running IIS on W2kServer and am trying to use ASP with some legacy X-Base tables. I cannot get the provider to connect. Relevant code is: strProvider =...
4
by: Erik Hendrix | last post by:
Hi, I have a quick question, when one sets the prefetch size = extent size, then when doing a backup we will have 1 agent (db2bm) doing the reads. If we have prefetch size a multiple of extent...
3
by: Lyle Fairfield | last post by:
Sometimes we use script or code whose variable types do not correspond to the variable types of other technologies with which they interface. It's possible that our db provider may come to our...
0
by: sriharim | last post by:
I am using DB2 UDB Application development client v8.2.5. I am trying to setup a linked server in MS SQL Enterprise Manager using the IBM OLE DB Provider for DB2 to connect to databases on DB2 for...
2
by: Soddy | last post by:
Hello! I'm playing with an Access 2003 (Converted Northwind & Split) DB. I 'copy & paste' the split Access DB into the 'Solution' of C#.NET and make the 'connection'. I then 'copy & Paste' the...
1
by: AppleBag | last post by:
Hello I have found examples of using an .mdb file in VS2K3, but apparently the components in the toolbox are different than the ones shown in the 2K3 examples. I have google'd and searched high...
5
by: ph3ng | last post by:
Hi I was executing sp_help on a server (ran against master database) and i get the following message: Associated statement is not prepared(HY007) Anyone got any idea what is wrong?
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...
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.