Converting between base 2, 10 and 16 in T-SQL
Lean how to convert between binary (base 2), decimal integers (base 10) and hexadecimal (base 16) using T-SQL.
Copying a SQL Server database file that’s in use using Volume Shadow Copy
Learn how to copy an online SQL Server data file that is in use, using the AlphaVSS Volume Shadow Copy (VSS) functionality in C#.
Saving space by storing decimal values in integer data types
Learn how to effectively store decimal values in SQL Server while taking up as little space as possible.
Converting page pointers into a human readable format
Learn how to convert the first_page, root_page, first_iam_page and general page pointers from hexadecimal to a human readable format.
Working with identity column seed & increment values
Learn how to find the current identity value of an identity column, how to change the seed & increment values, as well as how to retrieve the maximum and minimum values.
Controlling SqlConnection timeouts
Controlling the SqlConnection timeout can be tricky as there are multiple timeouts in effect. In this post I'll describe how to automatically timeout an open connection.
Weighted random selections in SQL Server
UPDATE After testing my code through based on JP’s comments, I’ve realized my implementation was way too naïve and cannot be used for most datasets. For a correct weighted random implementation, see Dems’ answer on StackOverflow. Original (flawed) implementation There are no built-in functions for selecting weighted averages in SQL Server. Fortunately it's a simple task to do so oneself. We'll use this table as an example: CREATE TABLE #tmp
(
Name varchar(64),
Points int
)
INSERT INTO #tmp VALUES ('Mark', 25);
INSERT INTO #tmp VALUES ('Jakob', 12);
INSERT INTO #tmp VALUES ('Peter', 17);
INSERT INTO #tmp VALUES ('Anders', 0);
INSERT INTO #tmp VALUES...
SQL Server datetime rounding made easy
Learn how to truncate & round SQL Server date & datetime values.