Reputation: 1307
I'm trying to execute a query to search 4 tables in a database using SQLQuery through Python. Every time I try and execute the following string as a query, it gives me the above error.
data2 = pd.read_sql("SELECT DateTime, vManagedEntity.DisplayName, vPerformanceRule.ObjectName, vPerformanceRule.CounterName, vPerformanceRuleInstance.InstanceName, SampleCount,AverageValue, MinValue, MaxValue FROM Perf.vPerfHourly INNER JOIN vPerformanceRuleInstance ON Perf.vPerfHourly.PerformanceRuleInstanceRowId =vPerformanceRuleInstance.PerformanceRuleInstanceRowId INNER JOIN vPerformanceRule ON vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId INNER JOIN vRelationship ON Perf.vPerfHourly.ManagedEntityRowId = vRelationship.TargetManagedEntityRowId INNER JOIN vManagedEntity ON vRelationship.SourceManagedEntityRowId =vManagedEntity.ManagedEntityRowId WHERE vPerformanceRule.ObjectName in ('Processor', 'Memory', 'Network Adapter', 'System', 'LogicalDisk') AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes', 'Pages/sec', 'PercentBandwidthUsedTotal', 'Bytes Total/sec', 'Processor Queue Length', '% Free Space', 'Avg. Disk sec/Transfer', 'Current Disk Queue Length') AND LEFT(DisplayName,7) not in ('Active ', 'AD Doma', 'Windows ') AND (DateTime BETWEEN '%s' and '%s')" % (maxDate,currentTime),cnxn)
I verified various forums but couldn't able to solve this, the Same query works if I remove maxDate and CurrentTime parameters. what am I missing here.
Upvotes: 0
Views: 765
Reputation: 133360
Seems you have a % in wrong place
....AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes',.....
try remove
....AND vPerformanceRule.CounterName in ('Processor Time', 'Available Mbytes', ....
or escape
Upvotes: 1