Archive

Archive for the ‘SQL Server’ Category

SQL Server String Functions

July 10, 2010 Rhonda Leave a comment

Manipulating strings is a common task in T-SQL. Below are a few of SQL’s built-in functions that make dealing with strings easier.

LEN – determines the length of a string value.
Syntax:  LEN ( string_expression )

LEFT – returns the specified number of characters from the left side of the string value.
Syntax:  LEFT ( character_expression, integer_expression )

RIGHT – returns the specified number of characters from the right side of the string value.
Syntax:  RIGHT ( character_expression, integer_expression )

SUBSTRING – returns the specified number of characters from the middle of the string value.
Syntax:  SUBSTRING ( expression, start, length )

REPLACE – replaces characters in the string
Syntax:  REPLACE ( string_expression, string_pattern, string_replacement)

STUFF – inserts characters in the string
Syntax:  STUFF ( character_expression, start, length, character_expression )

T-SQL Code Sample

DECLARE @testString VARCHAR(20)
SET @testString = 'Big Bang Theory'

SELECT LEN(@testString) AS _Length,
    LEFT(@testString,3) AS _Left,
    RIGHT(@testString,6) AS _Right,
    SUBSTRING(@testString,5,4) AS _Substring,
    REPLACE(@testString,'Bang', 'Bazinga') AS _Replace,
    STUFF(@testString,5,0,'Big ') AS _Stuff

T-SQL Listing on GitHub

T-SQL Code Sample – Result

image

^..^

Categories: SQL Server Tags: , , ,

Great T-SQL Resource: Beyond Relational

June 28, 2010 Rhonda Leave a comment

br

I recently ran across the site Beyond Relational. It is full of great information on SQL Server. My favorite areas of the site are T-SQL Challenges and T-SQL Challenges for Beginners.

Whether you are just learning T-SQL or sharpening your querying skills, these two areas contain some great assignments to learn from. Check them out.

^..^

HASSUG Meeting – 04/13/10 – Recap

April 25, 2010 Rhonda Leave a comment

For the first time in a while, I attended the Houston Area SQL Server User Group meeting and I am glad I did. Especially since I walked away with a free (signed) copy of the book SQL In A Nutshell.

hassug   sqlnutshell

The speaker was Kevin Kline (@kekline) and the topic was The Top 10 Mistakes on SQL Server.

High Points Gleaned

10.  Disks – Thinking space not IO (insufficient I/O, poor choice of RAID type, not enough spindles, etc.)

09.  Ignorance – As an IT professional you should know how SQL Server works at an “internals” level.

08.  No trouble-shooting methodology

07.  Going with the defaults – Autogrow/autoshrink on DB’s, default filegroups, etc.

06.  Security as an afterthought – SQL attacks are the #1 hack on the internet today.

05.  Inadequate automation

04.  Wrong feature or technique for the job

03.  Apathy without change management

02.  Inadequate preventative maintenance

01.  Backups <> Recovery

Links

Announcements

May Meeting: TUE 5/11 @ 11:30AM – How to Protect SQL Server with DPM 2010 – Presenter: Javier Calvillo, Microsoft

Special Meeting: TUE 5/18 @ 6:30PM – Essential Database Maintenance – Presenters: Kimberly Tripp & Paul Randal, SQLSkills

July Meeting: TUE 7/13 @ 11:30 – Topic TBD – Brent Ozar

^..^

Categories: Community, SQL Server

SQL Pass 2009 Recaps and Live Blogs

November 8, 2009 Rhonda 1 comment
Categories: Community, SQL Server

SQL Pretty Printer Add-In for SSMS – Review

September 13, 2009 Rhonda 3 comments

I came across an online Instant SQL Formatter a while back and have been using that for some time to format SQL code that I get from other people.  Now I see there is an add-in for SQL Management Studio from the same author of the online version. I downloaded and installed the SQL Pretty Printer Add-In For SSMS (not free) and have really found it very helpful.

Once installed, you will see the following toolbar in SSMS.

SQLPrettyPrinterForSSMS-1

I created a couple of quick queries without paying too much attention to formatting.

SQLPrettyPrinterForSSMS-2

Here is the same code after using the Pretty Printer SQL Formatter. Nice!

SQLPrettyPrinterForSSMS-3

There are also numerous settings for the formatting, which is also very cool.

SQLPrettyPrinterForSSMS-4

In closing, if you are like me and have an OCD when it comes to consistently formatted code, you will find this tool useful. The place where it is really useful and time-saving is on REALLY long Stored Procedures. I have had to deal with this lately, so I use this tool daily.

SQL Pretty Printer Add-In for SQL Server Management Studio

Instant SQL Formatter

Until next time…

SSMS Tip – Display Results in a Separate Tab

August 23, 2009 Rhonda 3 comments

One of my co-workers pointed out a setting in SQL Server Management Studio that has been extremely useful to me.  It is the [Display Results in a Separate Tab] setting. This setting is helpful if you want to see more T-SQL code and/or more data in the return set. I am a fan of both.

To enable this setting go to Tools > Options…

Select Query Results > SQL Server > Results to Grid — and check Display results in a separate tab as well as Switch to results tab after the query executes

ssms-tip-1

As you can see, when you execute a query, the results are displayed in their own tab.

ssms-tip-2

ssms-tip-3 

I have found this setting helps a lot with really long stored procedures.  It is nice to be able to see more code at one time.

Until next time…

Categories: SQL Server

SSMS Tools Pack – Review

August 7, 2009 Rhonda 1 comment

I downloaded the SSMS Tools Pack about 3 weeks ago at the urging of a co-worker. Boy I am glad I did.  There are many useful tools in this collection from Mladen Prajdic.

Below are the tools that I have used the most (and LOVE)

  • Text document Regions and Debug sections – This helps with very large Stored Procedures.  I know this because for the passed month, I have had to wade through very large ones.
  • Window Connection Coloring – This tool is awesome if you are having to constantly switch between Development, Staging and Production servers. It has already saved me several times.
  • New Query Template – Nice tool to help speed up creating a new query by defaulting in items from a template.

Other useful tools included in the pack

  • Query Execution History (Soft Source Control) and Current Window History.
  • Search Table or Database Data.
  • Uppercase/Lowercase keywords and proper case Database Object Names.
  • Run one script on multiple databases.
  • Copy execution plan bitmaps to clipboard.
  • Search Results in Grid Mode and Execution Plans.
  • Generate Insert statements for a single table, the whole database or current result sets in grids.
  • Running custom scripts from Object explorer’s Context menu.
  • CRUD (Create, Read, Update, Delete) stored procedure generation.

So far, I find the SSMS Tools Pack extremely useful and am happy my co-worker recommended it.

SSMS Tools Pack Website

Mladen Prajdic’s Blog

Mladen Prajdic on Twitter

Until next time…

SQL Server Resources – 7/11/09

July 11, 2009 Rhonda 1 comment

sql

I have run across a few great resources for SQL Server recently. Some are new and some have been around for awhile and I’m just discovering them.

Until later…

Categories: SQL Server

Converting Dates in SQL Server

January 18, 2009 Rhonda 1 comment

 

In the world of Application and DB Development there is always a need to display dates in a format that is understandable to your audience.  For example, in the US we normally expect to see a date as mm/dd/yyyy; however, in Great Britain, the normal format is dd/mm/yyyy.  The Convert function in SQL Server provides a means to translate SQL Server’s default date format to just about any format.

The syntax for the Convert function is as follows:

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Available Date Formats –

 Source Code

tsql

It shows some of the different ways dates can be formatted and produces the result below.

 

Below are a few resources that I found on using the Convert function.

I also posted a while back about Handling Dates in SQL Server.

Happy Learning!

Categories: SQL Server

PASS 2008 Resources

November 22, 2008 Rhonda Leave a comment

I rarely get to go to conferences unless they are local and cheap, so I try to focus on finding information from the conferences that I can’t be at. Below are some great resources that I have run across for the 2008 SQL PASS Community Summit.

I am sure there are a lot more resources that I have not seen.  I will update this post as I run across any more.