Solved

SQL text using cross apply

Posted on 2013-01-29
4
407 Views
Last Modified: 2013-01-29
Can someone tell me why the top query succesfully returns teh SQL text but the bottom one does not?



SELECT GETDATE(), *
FROM sys.sysprocesses
CROSS APPLY sys.dm_exec_sql_text(sql_handle)

SELECT 
GETDATE() AS datetime, spid, kpid, blocked, waittype, waittime, lastwaittype, waitresource, uid, cpu, physical_io, memusage, login_time, last_batch, ecid, open_tran, status, sid, hostname, program_name, hostprocess, cmd, nt_domain, nt_username, net_address, net_library, loginame, context_info, sql_handle, stmt_start, stmt_end, request_id
FROM sys.sysprocesses
OUTER APPLY sys.dm_exec_sql_text(sql_handle)

Open in new window

0
Comment
Question by:reticentKoala
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
liija earned 500 total points
Comment Utility
I can't see text-column in your bottom one...

try

SELECT
GETDATE() AS datetime, text
FROM sys.sysprocesses
OUTER APPLY sys.dm_exec_sql_text(sql_handle)
WHERE text is not NULL
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
I can't see text-column in your bottom one...
That would certainly explain it.  :)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
But seriously, you will get a value of NULL for text when there is no sql_handle as you are using OUTER APPLY.
0
 

Author Closing Comment

by:reticentKoala
Comment Utility
Doh. Thanks.

That's fine. I want to see processes even where there is no associated tsql.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now