Il codice seguente ha funzionato per me.
create table #Space(Drive varchar(4),SpaceAvailable varchar(15))
insert into #Space(Drive,SpaceAvailable)
exec xp_fixeddrives
Alter table #Space add FinalSpace as spaceavailable/1024
select * from #Space
Declare @FreeSpace int=0
select @FreeSpace=51 --(select top 1 FinalSpace from #Space)
print @FreeSpace
if (@FreeSpace between 0 and 50)
begin
print 'No Space Available'
end
if (@FreeSpace between 51 and 124 )
begin
backup database PerfDB to disk='E:\PerfDB.bak'
Print 'Loop Entered to E'
end
if (@FreeSpace between 125 and 150 )
begin
backup database PerfDB to disk='F:\PerfDB.bak'
Print 'Loop Entered to F'
end