Pad a string with leading zeros so it’s 3 characters long in SQL Server 2008

If the field is already a string, this will work SELECT RIGHT(‘000’+ISNULL(field,”),3) If you want nulls to show as ‘000’ It might be an integer — then you would want SELECT RIGHT(‘000’+CAST(field AS VARCHAR(3)),3) As required by the question this answer only works if the length <= 3, if you want something larger you need … Read more

Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?

Never ever should you use money. It is not precise, and it is pure garbage; always use decimal/numeric. Run this to see what I mean: DECLARE @mon1 MONEY, @mon2 MONEY, @mon3 MONEY, @mon4 MONEY, @num1 DECIMAL(19,4), @num2 DECIMAL(19,4), @num3 DECIMAL(19,4), @num4 DECIMAL(19,4) SELECT @mon1 = 100, @mon2 = 339, @mon3 = 10000, @num1 = 100, … Read more

What is the significance of 1/1/1753 in SQL Server?

The decision to use 1st January 1753 (1753-01-01) as the minimum date value for a datetime in SQL Server goes back to its Sybase origins. The significance of the date itself though can be attributed to this man. Philip Stanhope, 4th Earl of Chesterfield. Who steered the Calendar (New Style) Act 1750 through the British … Read more

SQL-Server: The backup set holds a backup of a database other than the existing

I too came across this issue. Solution : Don’t create an empty database and restore the .bak file on to it. Use ‘Restore Database’ option accessible by right clicking the “Databases” branch of the SQL Server Management Studio and provide the database name while providing the source to restore. Also change the file names at … Read more

Insert multiple rows WITHOUT repeating the “INSERT INTO …” part of the statement?

Your syntax almost works in SQL Server 2008 (but not in SQL Server 20051): CREATE TABLE MyTable (id int, name char(10)); INSERT INTO MyTable (id, name) VALUES (1, ‘Bob’), (2, ‘Peter’), (3, ‘Joe’); SELECT * FROM MyTable; id | name —+——— 1 | Bob 2 | Peter 3 | Joe 1 When the question was … Read more

What is the difference between Integrated Security = True and Integrated Security = SSPI?

According to Microsoft they are the same thing. When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true.