Hi, I have a SQL query which has previously been used within our IT dept which lists volumes, size, space left and works out how many months are left until volume is full.
What I want to do is date the number of months left til full "months_remains" and add it to the current date to find out a month/year. E.g. if a volume showed 12 months, I would output to show a date of November 2010 (as today is November 2009)
Can anyone assist in the SQL which I will need to add to achieve this.
I think I need to use DATEADD(month,months_remain,GETDATE()) AS full_date, but can get it to work as I get error.
Msg 207, Level 16, State 1, Line 5
Invalid column name 'months_remain'.
The query currently reads as:
SELECT Nodes.NodeID, Nodes.Caption AS NodeName, max(v.caption) as volume_name,
CAST(max(volumesize/1073741822.30351) AS DECIMAL(12, 2))as disksize_gb ,
CAST(max(volumespaceavailable/1073741822.30351) AS DECIMAL(12, 2)) as disk_remains ,
CAST((max(avgdiskused/1073741822.30351)-min(avgdiskused/1073741822.30351))/ count(distinct datename(mm,vd.datetime))AS DECIMAL(12, 2)) as avg_usage,
CAST(max(volumespaceavailable/1073741822.30351) / ((max(avgdiskused/1073741822.30351)-min(avgdiskused/1073741822.30351)+0.001) / count(distinct datename(mm,vd.datetime)+ datename(yy,vd.datetime)))
AS DECIMAL(12, 0)) as months_remains
FROM
nodes,VolumeUsage_Daily vd, volumes v
WHERE
nodes.nodeid=vd.nodeid
and vd.volumeid=v.volumeid
and nodes.nodeid=v.nodeid
and nodes.machinetype like '%Windows%'
GROUP by Nodes.Caption, Nodes.NodeID ,v.volumeid
ORDER by Nodes.Caption,v.volumeid