While working on a project recently I ran into an instance where I was creating a view in T-SQL that would need to select multiple results from a subselect and then put them into a single column within the view for use within a data grid. This needed to be done in order to maximize readability and ease of use.
Recently I came into a problem when I accidentally added a user to CRM that caused the entire CRM instance to no longer be usable. What happened is the user shared I added to an instance was the user that created the CRM instance. That cause the whole instance to throw an error any time anyone would load it up.
Recently I came across the need to insert the same unique identifier into two separate columns in the same insert statement. It turns out that it is a relatively easy solution but something that took a little bit of ingenuity.
So it’s not often, in fact I can’t think of many instances where you would need to insert the same unique identifier into two different columns in a single table in a single insert statement. As you may or may not know the easiest way to get a new unique identifier in T-SQL is using the command NEWID(). However, the problem is that if you make this call twice in a single statement you’ll get two unique identifiers.
There are a number of different reasons that you would want to get your database results in a random order. I’ve had a number of different reasons to do this so far throughout my career, the first of which was in a simple T-SQL statement that we were pulling up a list of items that we wanted in a random order. Turns out that with T-SQL there is a really simple way to get your results in a random order. All you have to do is add the following to the end of your SQL statement.