SQL text using cross apply

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

FROM sys.sysprocesses
CROSS APPLY sys.dm_exec_sql_text(sql_handle)

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

Question by:reticentKoala
  • 2

Accepted Solution

liija earned 500 total points
ID: 38830731
I can't see text-column in your bottom one...


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

Expert Comment

by:Anthony Perkins
ID: 38830963
I can't see text-column in your bottom one...
That would certainly explain it.  :)
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.

Author Closing Comment

ID: 38830973
Doh. Thanks.

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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

932 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

14 Experts available now in Live!

Get 1:1 Help Now