On the move:

I'm currently moving the following to their own blogs: Unix, HTML for Blogs, Perl & Java.
The links are on the left side.

Monday, May 26, 2008

SQL Query Layout

When the query gets a little long and it's hard to find anything, I've used the following kind of outline/layout. You may even want to number the virtual tables created based on the paragraph number. For example, a table would be 'vt121', which means it would have been created in paragraph 1.2.1. This way it's always easy to find where the code came from.
--+- 1 -------------------------------------------------------------------------
--|
--+-----------------------------------------------------------------------------
Select
From
--+- 1.1 -----------------------------------------------------------------
--|
--+-----------------------------------------------------------------------
(
Select
From
--+- 1.1.1 ---------------------------------------------------------
--|
--+-----------------------------------------------------------------
(
Select
From
--+- 1.1.1.1 ---------------------------------------------------
--|
--+-------------------------------------------------------------
(
Select
From
--+- 1.1.1.1.1 -------------------------------------------
--|
--+-------------------------------------------------------
(
Select
From
)
--+- 1.1.1.1 End -----------------------------------------------
--|
--+-------------------------------------------------------------
)
--+- 1.1.1 End -----------------------------------------------------
--|
--+-----------------------------------------------------------------
)
--+- 1.1 End -------------------------------------------------------------
--|
--+-----------------------------------------------------------------------
)
--+- 1 End ---------------------------------------------------------------------
--|
--+-----------------------------------------------------------------------------
;

No comments:

Post a Comment