This site is a storehouse for the random thoughts, tips, and musings of me and a few of my friends. We all have varied interests, so it should be a rather eclectic collection of posts.
If there's a particular topic or interest that you would like to hear about, let me know.
Recent Posts
Showing the 20 most recent posts in category 'GrowYourKnow'.
Concatenate Strings in TSQL
February 24, 2015
There several methods for building strings from multiple rows of data, but my favorite uses XML. This approach doesn’t require any loops or temporary variables (which cannot be used within a VIEW). Another benefit is that the resulting query can be used as a subquery, in a common table expression (CTE), or anywhere that a normal query would be used. -- init example data DECLARE @Data TABLE (Id int IDENTITY(1,1), Caption varchar(25)) INSERT INTO @Data...
» Show full post ...
Random Rows in TSQL
February 24, 2015
Sometimes it can be useful to randomly select a value (or row) from a table. One easy way to do this is to sort the table using a column that contains random values, and then select the first row. The following query illustrates this concept. -- initialize example data DECLARE @Data TABLE (Id int IDENTITY(1,1), Caption varchar(25)) INSERT INTO @Data (Caption) SELECT 'Apple' UNION SELECT 'Orange' UNION SELECT 'Banana' UNION SELECT 'Pear' UNION SELECT 'Mango'...
» Show full post ...
Truncate Dates in TSQL
February 24, 2015
There are many times when you want to store a pure date in the database. Examples include date of birth, anniversaries, date of hire, etc… Before the 2008 version of SQL Server, there was no pure date data type. Dates were stored in DATETIME columns. In another sceanrio, you may actually want to store the date and time, but perform queries on just the date part. For example, you may have a LastSeenOn column in...
» Show full post ...
Chromebook Home and End Keys
February 12, 2015
When transitioning from Windows to my MacBook Pro around 2009, I lamented the missing Home and End keys. I eventually discovered that the Command+Left and Command+Right combos performed the same action. It’s taken a while, but I’m finally comfortable with the usage. Fast forward to 2014. I got a shiny, new Chromebook from ASUS. Again, the Home and End keys were missing. Not a problem. I’m a pro at Command+Left and Command+Right now. Unfortunately, the...
» Show full post ...