Is today a weekend or a weekday? A question from the very first SQL Bangalore User Group meeting, answered with the CHOOSE function in SQL Server 2012.
Display Datetime in a Specific Format: CONVERT and FORMAT
To display datetime in a specific format, use CONVERT with a style number or FORMAT with a pattern. This post tests both on a fixed value, shows the lowercase pattern mistake, measures how much slower FORMAT is, and explains why parsing text dates needs a style.
SQL SERVER – Using RAND() in User Defined Functions (UDF)
Using RAND() in a user defined function throws Msg 443, invalid use of a side-effecting operator. Here is a simple workaround that lets a UDF use a random value.
SQL SERVER – Removing Leading Zeros From Column in Table
Most people ask how to keep leading zeros in SQL Server. This time a reader wanted to remove leading zeros and white space from a column, so here is a script.
Rename a Column or Table in SQL Server Safely
To rename a column in SQL Server, call sp_rename with the table and column name, the new name and the word COLUMN. This post tests the rename on a demo database and shows what it leaves behind: a broken view, an old constraint name and permissions that stay. It ends with a safe way to swap two column names.
Change Logs as JSON: Old and New Values in One Column
Skip the audit table with a column for every field. One JSON payload per changed row is lighter, if you handle NULL and multirow updates correctly.
Checking Certificates That Expire Soon in Every Database
Nobody remembers who created that certificate. Here is a short loop that lists every certificate expiring soon, and what to ask about each one.







