SQL - @@CPU_BUSY Function



The SQL @@CPU_BUSY statistical function is used to retrieve the amount of time that SQL server spent on an operation.

If the time returned by the @@CPU_BUSY function exceeds the 49 days of cumulative CPU time, then you may get an arithmetic overflow warning.

Syntax

Following is the syntax of the SQL @@CPU_BUSY function −

@@CPU_BUSY    

Return type

The return type of this function is an INTEGER.

Parameters

  • It does not accept any parameters.

Return value

It returns amount of time, SQL server spent on an active operation.

Example

In the following example,we are using the SQL @@CPU_BUSY function to retrieve the amount of time, that the SQL server has spent in active operations.

SELECT @@CPU_BUSY AS TOTAL_SPENT_TIME;

Output

Following is the output of the above query −

+-------------------+
| TOTAL_SPENT_TIME  |
+-------------------+
| 83269             |
+-------------------+

Example

The following is another example of the SQL @@CPU_BUSY function. You can also use the GETDATE() function along with this function to retrieve the amount of time until today that the SQL server has spent in active operation since its latest start.

SELECT GETDATE() AS 'TODAY''S DATE', @@CPU_BUSY AS TOTAL_SPENT_TIME;

Output

On executing the above program, it will produce the following output −

+-------------------------+------------------+
| TODAY'S DATE            | TOTAL_SPENT_TIME |
+-------------------------+------------------+
| 2023-02-28 12:26:50.940 | 83379            |
+-------------------------+------------------+
sql-statistical-functions.htm
Advertisements