Issues with "There is already an object named 'xxx' in the database'
- by Hoser
I'm fairly new to SQL so this may be an easy mistake, but I haven't been able to find a solid solution anywhere else. Problem is whenever I try to use my temp table, it tells me it cannot be used because there is already an object with that name. I frequently try switching up the names, and sometimes it'll let me work with the table for a little while, but it never lasts for long. Am I dropping the table incorrectly? Also, I've had people suggest to just use a permanent table, but this database does not allow me to do that.
create table #RandomTableName(NameOfObject varchar(50), NameOfCounter varchar(50), SampledValue decimal)
select vPerformanceRule.ObjectName, vPerformanceRule.CounterName, Perf.vPerfRaw.SampleValue
into #RandomTableName
from vPerformanceRule, vPerformanceRuleInstance, Perf.vPerfRaw
where (ObjectName like 'Processor' AND CounterName like '% Processor Time')
OR(ObjectName like 'System' AND CounterName like 'Processor Queue Length')
OR(ObjectName like 'Memory' AND CounterName like 'Pages/Sec')
OR(ObjectName like 'Physical Disk' AND CounterName like 'Avg. Disk Queue Length')
OR(ObjectName like 'Physical Disk' AND CounterName like 'Avg. Disk sec/Read')
OR(ObjectName like 'Physical Disk' and CounterName like '% Disk Time')
OR(ObjectName like 'Logical Disk' and CounterName like '% Free Space' AND SampleValue > 70 AND SampleValue < 100)
order by ObjectName, SampleValue
drop table #RandomTableName