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.messages. Where is this error message coming from then?

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. Registration was hiccup free (though I was early and missed the rush), rooms were all located in close proximity to one another, and the lunch room flowed pretty quickly despite an early line. The signs and schedule were excellent, with 8.5 ×11 placards posted for all of the sessions on each room’s door as well as large grids posted on the wall in two locations, displaying the whole schedule. Once I figured out the room numbering, it was easy to locate the sessions or speakers I was interested in. The event was organized by members of TriPASS, the local SQL Server User Group in Raleigh, and I’m looking forward to getting involved with the next one they put together. If I had to pick one element of the event that characterized it the most, that element would be how smoothly the execution went.

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. One of those events was becoming a SQL Server MVP in July. Since then I have probably said it more times than my close friends can stand to hear anymore but I still don’t think I do a lot to give back to the community to gain this exceeding accomplishment. For years I have looked at the MVP awards as an extremely prestigious accomplishment. I owe special thanks to Jonathan Kehayias (blog | twitter) and Denis Gobo (blog | twitter). Both of these MVPs saw in me what were MVP characteristics and paved the way for me to be recognized as such. One of the coolest parts of this award is there are many other MVPs that I have talked to that feel exactly the same way in not feeling they do as much as we think we do. That is the reason they should have the MVP award. I’ve said it many times in my writing that the community leaders show no greed in what they do. That characteristic is what makes a leader and a trusting one. There are a lot of these people I look up to and have for many years. Being in the same group as them has truly given me the energy to push my efforts to the next level.

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.

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! Even the speakers gain more from speaking when the group gets into it. There were some takeaways of my own that I will write up based on some questions and promises to the group (yes, I haven’t forgotten). I hope to have those posted very soon. One was the baseline collection that I have mentioned over the past few weeks. This was based off a blog series that I discussed on collecting and making baselines a must with your SQL Server environments. I’m writing a new series of packages to handle this in a friendly and portable upload for everyone and hope to have it done soon.

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. Disadvantage here is it scans the entire table (if it’s heap) or Clustered Index.

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. These events are free and organized by people just like you and I. That means they know what you want to hear and how to present that information to you. (Not to mention the awesome prizes that sponsors give out in the raffle)

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 Let’s take a look at another example, but instead of using print we will use a SET @param = value statement. Can you guess what @SomeCount will return in the select statement?

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][1]. 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. Every time I commit somewhere, a server starts to build the project and run the unit tests like magic. But now it is time to move on and lose some time with learning a new thing again. I guess using Github or some other third party external thing would be cool but it is not an option in my line of business.

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#. Now take a look at this:

Read More...