SQL Blog of Zach Stagers

www.scratchbox.co.uk

Keyboard Shortcut to Upper or Lower Case Code in SSMS

No Comments »

If, like me, you like your code to be formatted in a specific way, then this little shortcut may save you a bit of time when you need to pick up and modify someone elses code.

For example, I like all of my SQL keywords to be written in upper case letters, so if I find one that isn’t in a colleagues code – I simply highlight the text with my cursor then press CTRL + SHIFT + U to make all of the letters upper case.

The reverse of this, should you ever need to make letters lower case is CTRL + SHIFT + L.

Finding Duplicates With Excel 2010

No Comments »

A handly little tool within Microsft Excel is Conditional Formatting, you can perform many look ups with it, but in the post I’ll be explaining how to find duplicate values.

Start off by highlighting the cells that you’d like to check for duplicates. Then locate the Conditional Formatting button, which can be found on the Home tab. Navigate through the drop down menu to “Highlight Cells Rules” then “Duplicate Values…” as below:

ConditionalFormatting

The Duplicate Values Dialogue box will pop up for you too select a few options from. The value set to “Duplicate” can be changed to “Unique”, depending on what you’d like to search for. The second drop down is just preference, and can be set to whatever you’d like – it determines the colour the cells containing the duplicate values will be set to.

DuplicateValuesDialogue

With the options above set, and all cells in the workbook selected, the below is the result. This can then be filtered and modified as you please, the duplicate values will remain highlighted until one of them is removed:

DuplicateCells

SQL Coalesce

No Comments »

I’ve been using this sytem function a lot lately, and it’s really useful!

I’m having to check for a phone number in several different places, and using Coalesce helped me avoid using a long drawn out Case Statement.

COALESCE(expression 1, expression 2, expression 3) [Phone Number]

The above code will be placed in your column select list. The Coalesce will check expression 1 (The first column you want to check) for a value, and if one is found, it will be returned, but if it’s NULL, then expression 2 will be checked, if that’s NULL, then expression 3 will be checked.

The function will check all of the expressions listed within the bracers until a value is found, so if expression 1 has a value, it will be returned and the function wont bother checking the others. If all of the expressions listed are NULL, then a NULL will be returned.

The “[Phone Number]” will just name the column “Phone Number” in the result set.

You may pass in as many expressions as necessary, but remember – the more expressions the function has to check, the worse your performance will be.

Rotating Graph Data Labels in SSRS 2K8

No Comments »

The default settings for Data Labels attached to graphs can cause issues with overlapping, which in turn reduces readability.

In order to rotate the labels, select your graph, then select a single data label (each of them will be highlighted and affected by any changes). Open the properties window whilst the data labels are selected, and expand the “Label” title, then expand the “Labels” tag in the Label category. You’ll be presented with the below properties:

Graph Data Label Properties

As you may have guessed, the “Rotation” attribute controls the angle of the label. By default, this is set to zero, which will give you horizontal text.

A value of -90 to 90 can be selected. Any number below zero will swing the end of your text upwards, while any number above zero will tilt the end of your text downwards. The below is the result of the above properties, in this example -90 degrees is selected:

Graph with improved Data Labels