The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Bendono (9) [Avatar] Offline
#1
Great book. I have just begun reading it and am already using parts of it in my work.

In your SQL statements, you often mark lines with #A, #B, #C... with corresponding commentary at the end. For example, from page 13:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT TOP 20
CAST(total_elapsed_time / 1000000.0 AS DECIMAL(28, 2)) #A
AS [Total Elapsed Duration (s)]
, execution_count
, SUBSTRING (qt.text,(qs.statement_start_offset/2) + 1, #B
((CASE WHEN qs.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE
qs.statement_end_offset
END - qs.statement_start_offset)/2) + 1) AS [Individual Query]
, qt.text AS [Parent Query]
, DB_NAME(qt.dbid) AS DatabaseName
, qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
INNER JOIN sys.dm_exec_cached_plans as cp
on qs.plan_handle=cp.plan_handle
ORDER BY total_elapsed_time DESC #C

While the intent is obvious, when copying these statements (at least from the eBook), these will need to be manually edited before running. Is there another way that these could be expressed? Ideas off the top of my head:

1) While it may depend on how the PDF is generated, if the #A, #B, #C... portions are separated into a separate table, then they may not be selected when copying the code.
2) Prefix each with a -- to turn them into a comment.

Regards.
ian.stirk (27) [Avatar] Offline
#2
Re: #A, #B, #C...
Hi Bendono,

I'm glad you like the book, and find it practical for your work (as you might have guessed, I use it every day in my work too).

I will pass on your comments to manning to see if anything can be done to make things easier. Eventually, there will be a separate code download that doesn't contain these 'comments'.

Thanks again
Ian