MS SQL

Escape underscore(_) in LIKE statement
To escape underscore(_) in LIKE statement, you have to enclose the underscore(_) inside square brackets.
-- Select all values that end with _B.
SELECT *
FROM TableA
WHERE TableA.col LIKE '%[_]B';
Check SQL Server version and edition
SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition');
Copy all data of a table to another 1
--Copy all data of tableName to newTablename
SELECT * INTO newTablename FROM tableName 
 
 
-- Update data of fields from fromTable to toTable where their IDs match
--  This useful when you made a data copy of a table and then you want to revert the original data back.
UPDATE toTable
SET
  toTable.field1 = fromTable.field1, 
  toTable.field2 = fromTable.field2, 
  toTable.field3 = fromTable.field3, 
  toTable.fieldX = fromTable.fieldX, 
 
FROM fromTable
  INNER JOIN toTable ON toTable.field_ID = fromTable.field_ID
Date manipulation
--Example of date manipulation
UPDATE tablename SET dateField=DATEADD(DAY, -1, GETDATE()) WHERE (dateField = CONVERT(DATETIME, '2009-01-30 00:00:00', 102))
Search for column name in database
--Search for column name
SELECT TABLE_NAME=sysobjects.name,
    column_name=syscolumns.name,
    datatype=systypes.name,
    LENGTH=syscolumns.LENGTH
FROM sysobjects
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
WHERE syscolumns.name LIKE '%columnName%'