Solved

SQL text using cross apply

Posted on 2013-01-29
4
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
liija earned 500 total points
ID: 38830731
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
ID: 38830963
I can't see text-column in your bottom one...
That would certainly explain it.  :)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38830972
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
ID: 38830973
Doh. Thanks.

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

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

691 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