This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
SQL SERVER - Find Weekend and Weekdays from Datetime in SQL Server 2012

SQL SERVER – Find Weekend and Weekdays from Datetime in SQL Server 2012

November 25, 2012
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL Server, SQL Server 2012

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.

Read More
Gouache painting of two shelves holding the same three jars in opposite orders, the short jar on the top shelf painted red

Display Datetime in a Specific Format: CONVERT and FORMAT

November 21, 2012
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL String

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.

Read More
SQL SERVER - Using RAND() in User Defined Functions (UDF)

SQL SERVER – Using RAND() in User Defined Functions (UDF)

November 20, 2012
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Scripts, SQL Server

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.

Read More
SQL SERVER - Removing Leading Zeros From Column in Table

SQL SERVER – Removing Leading Zeros From Column in Table

November 19, 2012
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Scripts, SQL Server

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.

Read More
Gouache painting of a wooden boat with a bare stern panel and a pot of red paint with a brush waiting beside it

Rename a Column or Table in SQL Server Safely

November 14, 2012
Pinal Dave
SQL Tips and Tricks
SQL Column, SQL Scripts, SQL Server Management Studio, SQL Table Operation

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.

Read More
Darning mushroom supporting a sock with a small repaired patch

Change Logs as JSON: Old and New Values in One Column

November 12, 2012
Pinal Dave
SQL Tips and Tricks
JSON, SQL Scripts, SQL Server

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.

Read More
Grafting knife and prepared scion beside an older intact graft

Checking Certificates That Expire Soon in Every Database

November 8, 2012
Pinal Dave
SQL Tips and Tricks
SQL Scripts, SQL Server, SQL Server Security

Nobody remembers who created that certificate. Here is a short loop that lists every certificate expiring soon, and what to ask about each one.

Read More
Previous 1 … 197 198 199 200 201 202 203 … 366 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com