Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA query SQL Server FILEPROPERTY Not Returning

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
0
0
GB
Hi All,

I wonder if you can help me, I'm trying to return some values using a connection from Excel to SQL Server.

The code I'm using is as follows:

Code:
select name, filename, convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
    , [COLOR=#EF2929][b]convert(decimal(12,2),round(fileproperty(a.name,''SpaceUsed'')/128.000,2))[/b][/color] as SpaceUsedMB
    from myDB.dbo.sysfiles a

This correctly returns each of the names, the filename and the "FileSizeMB" correctly, however, the "SpaceUsed" (Highlighted) isn't working.

I've tested it in SQL Management studio and it works correctly and I've stripped it down to the bear essentials and it still doesn't work.

Code:
select name, fileproperty(a.name,''SpaceUsed'') as SpaceUsedMB
    from myDB.dbo.sysfiles a

Anyone got any ideas why this would be the case and how I can get it to work??

Thanks all

Fitz


Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 

hi,

Maybe...
Code:
select
  [highlight #FCE94F]a.[/highlight]name
, [highlight #FCE94F]a.[/highlight]filename, convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
, convert(decimal(12,2),round(fileproperty(a.name,''SpaceUsed'')/128.000,2)) as SpaceUsedMB

from myDB.dbo.sysfiles a

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi Skip,

I'll give it a shot, but the problem isn't with the name or filename fields, it's with the "FILEPROPERTY" part. :-S [bigears]

Fitz

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Found the issue. Incase anyone else comes across this, I had connected to the Server, but had not connected to the database.

The FILEPROPERTY "SpaceUsed" returns NULL for any Database that is isn't connected to. ie I needed to specify the connection directly to that DB and then all works ok!!!

Thanks for your help skip,

Regards,

Fitz

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Umh, just a guess, but when I copy your SQL and try to run in SQL Server, it gives an error because you have TWO single quotes around ~SpaceUsed~ (see how I avoided trying to say or use the forbidden character?(


The speculative judgment of the quality of an answer is based directly on … what was the question again?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top