Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQLStudies

My name is Kenneth Fisher and I am Senior DBA for a large (multi-national) insurance company. I have been working with databases for over 20 years starting with Clarion and Foxpro. I’ve been working with SQL Server for 12 years but have only really started “studying” the subject for the last 3. I don’t have any real "specialities" but I enjoy trouble shooting and teaching. Thus far I’ve earned by MCITP Database Administrator 2008, MCTS Database Administrator 2005, and MCTS Database Developer 2008. I’m currently studying for my MCITP Database Developer 2008 and should start in on the 2012 exams next year. My blog is at www.sqlstudies.com.

ORDER BY the numbers

Have you ever needed to order by a calculated column? You might have written it something like this:

SELECT LoginID, YEAR(HireDate) AS HireYear, 
	MONTH(HireDate) AS HireMonth
FROM HumanResources.Employee
ORDER BY YEAR(HireDate), MONTH(HireDate),
	LoginID

Did you know you don’t have to put the calculations in the ORDER BY? You don’t even… Read more

0 comments, 96 reads

Posted in SQLStudies on 17 June 2013

Best practice recommendations for writing Dynamic SQL

Note this is not “Best Practices when USING Dynamic SQL”. These are just good habits I’ve come up with over the years to make sure that when writing my dynamic SQL it breaks less often. Note I don’t say “doesn’t break ever”, dynamic SQL is tricky stuff. The best you… Read more

11 comments, 2,813 reads

Posted in SQLStudies on 12 June 2013

Using the OVER clause

Over the last few years I’ve learned quite a bit about different techniques in SQL Server. This particular one has been available since SQL 2005 and looks like it could be really handy.

Let’s say I want to calculate the total sales for by month and at the same the… Read more

0 comments, 111 reads

Posted in SQLStudies on 10 June 2013

Easy way to generate a restore script.

Easy way to generate a restore script.

I was asked today if I had a canned restore script handy. I don’t. I’ve never really had a reason to. Generating a restore script, even a complicated one is really very easy if you know how.

For those of you wondering, there… Read more

0 comments, 151 reads

Posted in SQLStudies on 5 June 2013

Pattern searches beyond ‘%string%’.

I was asked today to take a table with a social security column and put all 0s if the column had any letters in it. This is the typical social security column that actually has more rows with ‘XXX-XX-XXXX’ than it does valid SSNs. There are even cases that look… Read more

3 comments, 149 reads

Posted in SQLStudies on 3 June 2013

Backup a password, change it, then restore it.

A couple of months ago I talked about moving a login from one server to another without the password. The basis behind this is creating the login using the hashed version of the password. Using the same idea we can also “back up” a password.

The first thing to… Read more

0 comments, 933 reads

Posted in SQLStudies on 30 May 2013

Using CROSS APPLY to calculate an aggregate across a single row.

I’ve had CROSS APPLY on the mind recently. You could probably tell since its been the subject of my last two posts. Since it’s been on my mind a lot I started to wonder if I could use it to solve some problems I’ve run across in the past. In… Read more

2 comments, 160 reads

Posted in SQLStudies on 28 May 2013

Using CROSS APPLY instead of a calculated variable

Earlier this week I posted The many uses of CROSS APPLY and I’m quite glad I did. I’ve been working on a series of audit queries for the last couple of weeks and got thrown a bit of a curve today. The original specs included several comparisons against a date.… Read more

2 comments, 129 reads

Posted in SQLStudies on 22 May 2013

The many uses of CROSS APPLY

Over the last few years of studying SQL I’ve noticed 4 different uses for the command CROSS APPLY.

In the first use I ever saw, and certainly the one I see the most commonly, CROSS APPLY is used to run a function for each row of the query. This is… Read more

2 comments, 2,909 reads

Posted in SQLStudies on 20 May 2013

CREATE SCHEMA can do what?!?!?

So I was studying for the 70-451 and ended up reading the BOL entry for CREATE SCHEMA. I honestly can’t remember why, but what I do remember is thinking “CREATE SCHEMA can do what?!?!?” but with maybe a few more exclamation points.

Now I had always thought that CREATE SCHEMA… Read more

3 comments, 2,779 reads

Posted in SQLStudies on 15 May 2013

Dragging a name from the object explorer to a query window

In the same vein as Steve Jones’ series on Customizing SSMS this is a fairly basic trick, but one that not everyone appears to know.

A fairly standard layout of SSMS looks like this.

If you drill down, to say the table list, you can left-click and drag a table… Read more

5 comments, 2,212 reads

Posted in SQLStudies on 13 May 2013

Free SQL Books

I was looking for a way to put BOL on my Kindle when I found a few good links I thought I would share. FYI If anyone knows how to put BOL on an Android device it would be great!

Here is a link to large list of Microsoft books Read more

4 comments, 320 reads

Posted in SQLStudies on 8 May 2013

GO

Did you know that the GO command isn’t really part of T-SQL? It’s what’s called a batch separator. And in case you were wondering that’s why you can’t put GO inside of stored procedures, functions etc.

So what does the “batch separator do? Well, it separates batches of course. Working… Read more

2 comments, 145 reads

Posted in SQLStudies on 6 May 2013

Comparing an inner join vs a subquery

I was reading through Stackoverflow today and saw an interesting question. SQL inner join vs subquery. The user was comparing 3 queries and wondered why the first took significantly longer than the other 2.

Here are the queries:

Query 1: SELECT * From TabA INNER JOIN TabB on TabA.Id=TabB.Id…

Read more

10 comments, 3,844 reads

Posted in SQLStudies on 3 May 2013

Well I finally passed the 70-451

So I am now an MCITP Database Developer for SQL 2008. This is a big milestone for me. A few years ago I was terrified to take any of the exams. They are expensive, and I just knew there was no way I was going to pass. It would be… Read more

2 comments, 185 reads

Posted in SQLStudies on 1 May 2013

INFORMATION_SCHEMA the un-sung system views

I spend a reasonable amount of time looking through various forums, answering some questions and reading the answers to others. One of the things I’ve noticed is that while I frequently see system views referenced I only very rarely see the INFORMATION_SCHEMA views mentioned. This seems rather strange to me… Read more

0 comments, 180 reads

Posted in SQLStudies on 29 April 2013

How do I tell the stored procedure name from inside the stored procedure?

I’ve occasionally had the problem of trying to put “smart” logging messages into a process. You know the ones, you’re trying to set up logging for a process and you really want to create a somewhat generic piece of code that you can throw into each stored procedure. Something that… Read more

1 comments, 156 reads

Posted in SQLStudies on 24 April 2013

Who writes your documentation?

I’ve been thinking recently about who writes the best documentation. Not including a professional technical writer (although they actually do fit into my conclusion). On first thought I would have thought the SME (subject matter expert) would of course write the best documentation, because they understand the processes best. Upon… Read more

2 comments, 138 reads

Posted in SQLStudies on 22 April 2013

Calculating the length of a string (Len vs DataLength)

This one is basic but still something that can catch you unawares if you aren’t careful. Most DBAs and developers I know use the function LEN to calculate the length of a string. Little wonder since that is exactly what this function is for. However not everyone realizes the small… Read more

0 comments, 55 reads

Posted in SQLStudies on 15 April 2013

How do I use a variable in an IN clause?

I see this question in one form or another a lot. I’ve seen this or something like it probably half a dozen times in the last couple of weeks on the forums I read. To the point where it even showed up in a dream the other night (I know,… Read more

0 comments, 171 reads

Posted in SQLStudies on 8 April 2013

Older posts