Author |
Topic  |
khtan
In (Som, Ni, Yak)
Singapore
17689 Posts |
Posted - 03/28/2012 : 04:57:59
|
quote: Originally posted by parameshjoy
Msg 137, Level 15, State 2, Line 2 Must declare the scalar variable "@total".
Getting this error for query provided
Paramesh
you need to declare it. You must have missed that line. Double check your query
KH Time is always against us
|
Edited by - khtan on 03/28/2012 04:58:47 |
 |
|
parameshjoy
Starting Member
India
12 Posts |
Posted - 03/28/2012 : 05:10:08
|
DECLARE @total INT
SELECT @total=sum(cpu) FROM sys.sysprocesses sp (NOLOCK)
join sys.sysdatabases sb (NOLOCK) ON sp.dbid = sb.dbid
Insert into dbo.CPUdata ([database], [system cpu], [database cpu], [%]) SELECT sb.name 'database', @total 'system cpu', SUM(cpu) 'database cpu', CONVERT(DECIMAL(4,1), CONVERT(DECIMAL(17,2),SUM(cpu)) / CONVERT(DECIMAL(17,2),@total)*100) '%'
FROM sys.sysprocesses sp (NOLOCK)
JOIN sys.sysdatabases sb (NOLOCK) ON sp.dbid = sb.dbid
--WHERE sp.status = 'runnable'
GROUP BY sb.name
ORDER BY CONVERT(DECIMAL(4,1), CONVERT(DECIMAL(17,2),SUM(cpu)) / CONVERT(DECIMAL(17,2),@total)*100) desc
In the first line of the query i have already Declared it...
I have executed the query provided by Visakh's...
Paramesh |
 |
|
khtan
In (Som, Ni, Yak)
Singapore
17689 Posts |
Posted - 03/28/2012 : 05:12:47
|
Good for you. All is working right ?
KH Time is always against us
|
 |
|
parameshjoy
Starting Member
India
12 Posts |
Posted - 03/28/2012 : 05:33:13
|
Yes everything is working fine as i required.
Thanks for your help and sorry for confusion
Paramesh |
 |
|
khtan
In (Som, Ni, Yak)
Singapore
17689 Posts |
Posted - 03/28/2012 : 05:57:53
|
you are welcome
KH Time is always against us
|
 |
|
visakh16
Very Important crosS Applying yaK Herder
India
52326 Posts |
Posted - 03/28/2012 : 11:51:49
|
Hmm...didnt realise it went so far ... Is it so difficult to copy paste the given query and test it in SSMS window?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
Topic  |
|