Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Debugging CTEs

$
0
0
An annoyance for me is that a CTE doesn't seem to allow me to highlight-a-section-and-execute as I can with a SQL statement without a CTE.For example, if I have[code]SELECT Col1, Col2, ... long list of columns ...-- SELECT COUNT(*)-- [highlight="#FFFF00"]SELECT TOP 10 * FROM MyTable JOIN SomeOtherTables ...[/highlight][/code]I can select, from the bottom up, to include one of the commented out SELECT statements. Maybe I'm alone in this approach! but I do this A LOT.Delete example:[code]DELETE D-- SELECT COUNT(*)-- [highlight="#FFFF00"]SELECT TOP 10 * FROM MyTable AS D JOIN SomeOtherTables ...[/highlight][/code]Update example:[code]UPDATE U SET-- [highlight="#FFFF00"]SELECT TOP 100 Col1, Col2, Col3 = 'Foo'-- SELECT COUNT(*)-- SELECT TOP 10 * FROM MyTable AS U JOIN SomeOtherTables ...[/highlight][/code]With CTE I haven't been able to find a similar method, other than having to comment-out and back in again the whole of the SELECT section - which itself may contain /* */ comments :-([code];WITH CTE AS( SELECT ID, Col1, Col2 FROM MyTable WHERE ...)/* possible comment */SELECT Col1, Col2,/* possible comment */ ... long list of columns ...-- SELECT COUNT(*)-- SELECT TOP 10 * FROM CTE AS C JOIN MyTable AS T ON T.ID = C.ID...[/code]any suggestions please? Anyone else do this, or am I the only one?!!

Viewing all articles
Browse latest Browse all 3145

Trending Articles