Archives for category: dba

In a query pane in Aqua Data Studio… turn a query that looks like this:

into a beauty, like this:

All by pressing CTRL+B.

For the text equivalent:

select m.city, m.st, count(*)
from ___________ m 
inner join ____________ z
on m.city = z.city and 
m.st = z.state and
m.zip = z.zip_code WHERE
m.zip > '' AND 
m.st > '' AND 
m.city > '' AND 
z.city is null AND 
z.state is null and 
z.ZIP_CODE is null
group by m.city, m.st, m.zip 
HAVING count(*) <= 1 ;

into:

SELECT
	M.CITY,
	M.ST,
	COUNT(*) 
FROM
	__________ M 
		INNER JOIN __________ Z 
		ON M.CITY = Z.CITY AND
		M.ST = Z.STATE AND
		M.ZIP = Z.ZIP_CODE 
WHERE
	M.ZIP > '' AND
	M.ST > '' AND
	M.CITY > '' AND
	Z.CITY IS NULL AND
	Z.STATE IS NULL AND
	Z.ZIP_CODE IS NULL 
GROUP BY
	M.CITY,
	M.ST,
	M.ZIP 
HAVING
	COUNT(*) <= 1

I don’t know why I have this habit, but typically I write most of my queries in lowercase. All lowercase. Once I’m ready to publish them or have them reviewed, I’ll convert everything applicable (some parameters don’t need to be made uppercase) to uppercase.

CTRL+SHIFT+U converts your text selection to uppercase. CTRL+SHIFT+L converts your text selection to lowercase.

After you’ve parsed your query, in SQL Server, just press F5 and the query will be executed.

Instead of going up to the check mark to parse your query for syntactic goodness, just press CTRL+F5.

Follow

Get every new post delivered to your Inbox.