WHERE clause allignemnt with multiple levels

wolfixxwolfixx Posts: 5 New member
Hi,

This is the WHERE part of a query after I applied SQL Prompt formatting.
As you can see when I add a sub level after AND with 2 opening brackets they appear on the same level


....
WHERE ExportWorkspacePathRank = 1
      --New documents or updates detected
      AND (
          (
              SELECT COUNT(*) FROM DocumentList WHERE ExportChangeDeteched = 1
          )   > 0
          OR
          --Document deletes detected
          (
              SELECT COUNT(*) FROM DocumentList
          )   <
          (
              SELECT COUNT(*)
              FROM dbo.ExportDocuments
              WHERE ExportID =
              (
                  SELECT MAX(ExportID) FROM dbo.ExportDocuments
              )
          )
          );

Ideally the code should look liek this:
WHERE ExportWorkspacePathRank = 1
      --New documents or updates detected
      AND (
		  (
			  SELECT COUNT(*) FROM DocumentList WHERE ExportChangeDeteched = 1
		  )   > 0
		  OR
		  --Document deletes detected
		  (
			  SELECT COUNT(*) FROM DocumentList
		  )   <
		  (
			  SELECT COUNT(*)
			  FROM dbo.ExportDocuments
			  WHERE ExportID =
			  (
				  SELECT MAX(ExportID) FROM dbo.ExportDocuments
			  )
		  )
          );

Is this possible with SQL Prompt?

Thanks,
Wolfgang
Tagged:

Comments

Sign In or Register to comment.