LessThanDot Site Logo

LessThanDot

A decade of helpful technical content

This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.

How to capture the error output from xp_cmdshell in SQL Server

A person asked the following question: I am running the following command: EXEC @ReturnCode = master.dbo.xp_cmdshell @cmdline On the Results tab I get 2 lines Could not find a part of the path ‘serverdirectoryfilename’. NULL How do I capture the first line in an error message? I tried using a Try Catch block with “SELECT @ErrorMessage = ERROR_MESSAGE()” and it doesn’t grab it. The message is not coming from sys.

Read More...

SQL Saturday #46, Raleigh NC

It’s been a few days since SQL Saturday 46 and I have finally found some time to jot down my recap. This was the first Raleigh SQL Saturday and it lived up to all of my expectations. The Event The excellent group of volunteers that pulled it all together There were 6 tracks of events, which were balanced more towards the BI and SSIS side of things than the previous events I’ve attended.

Read More...

Doing this for the SQL Community

This post is long overdue but the last few months have been very busy. Busy in a great way though. That great way has been working on community and other things that we all know, I love to do. Some things have happened this year that have far surpassed my expectations of where I would be by now in my career and ability to give back to all of you.

Read More...

Accurately Simulating Movement of a Tracked Vehicle in 2D Space

As part of a simulation I’ve been developing I recently had to decide how to model movement of vehicles within a 2D space. To keep things simple I settled on a tracked vehicle. Each time the simulation updates I calculate how much the vehicle rotates and how far it moves based on the speed of it’s tracks. From there I calculate the new coordinates for redrawing the vehicle. Knowing the current location (x,y) and heading (h) I initially adopted a simplified way to calculate the rotation (g) and speed (s) based on the speed of the vehicle’s tracks (T1 and T2) (Figure 1).

Read More...

Have SQL, will travel – East Iowa SQL Saturday

This past weekend I traveled to Iowa City to hold a session on SSIS basics. The drive was worth it (even the hours looking at the back of a semi while the highway was at a dead stop). My session went extremely well and the group that attended the session was interactive and we all had a great time together. Interactive groups always make sessions more enjoyable. Ask questions and give your own experiences!

Read More...

Performance implications using NewID() in Random order

Today, I came across a question in MSDN forums “How to pick 5 random records?”. In SQL Server the only consistent way I know is to use NEWID() function in the Order By Clause. select top 5 * from Orders order by NEWID() This approach will always scan the entire table irrespective of number of rows requested. It retrieves each record in the table, appends a new GUID for each row, then based on that GUID it sorts the rows and presents the top 5 rows.

Read More...

SQL Saturday Iowa

Last year I attended SQL Saturday in Iowa and enjoyed it immensely. I was glad to see a follow up for this year coming this Friday, September 18th. This year I’m very happy to announce that I will be attending Iowa’s second SQL Saturday and also contributing as a speaker. If you have never been to a SQL Saturday event, I highly recommend attending this one or another in your area.

Read More...

When should you store @@ROWCOUNT into a variable?

There was a question I answered the other day where someone complained that the rowcount was always 0. Below is a simplified version of the query, can you tell why @SomeCount will be 0? declare @SomeCount int select 1 union all select 2 print '1' select @SomeCount = @@rowcount select @SomeCount The value that the @SomeCount parameter returns will be 0 because print resets the value of @@ROWCOUNT to 0

Read More...

Working with Git my first impressions

Introduction A couple of weeks ago I introduced myself to the world of the world of Git and Github. And I did not see much wrong with it. But over the last couple of years I have become very frustrated with the slowness of SVN – or it could just be TortoiseSVN. Anyway, I thought it was time for a change. I am still a lonely developer in a non-IT oriented workplace, so I mainly use source control for Backup as well as for easy Continuous Integration.

Read More...

Productive Programing With Pattern Matching

Personally I have been sold on F# for a long time but some people however will need a lot of convincing before they move out of their comfort zone. Hopefully after reading this you will be more inclined to try it out. Imagine you were given a directory full of files that did not have any file extensions and were told to figure out the file extension for every file. Picture how you might do this in VB or C#.

Read More...