Reset identity column back to 1
Sometimes have to run command more than once to reseed
DBCC CHECKIDENT ('[Table]', RESEED, 1)
See what is inside a stored procedure without modifying it
sp_helptext N'[Stored Procedure Name]'
Get the last character of a column if the letter isn't displaying
select AscII (right(sku,1) ) as lastchar
Put Stored Procedure Result Into Table
declare @table Table([Object Name] varchar(100), txt varchar(500)) insert into @table Exec '[Stored Procedure Name]' @params select * into #temp from @table
No lock - We can read the table even if something else is accessing the table
SELECT COUNT(*) FROM SalesHistory WITH(NOLOCK)
Read Past - Doesn't return locked records
SELECT COUNT(*) FROM SalesHistory WITH(ReadPast)
Pivot Example
select * from ( select convert(varchar(2), od.AddedDate, 101) as dateadded, sum(od.qty) as totalqty, UPC from Detail od where year(od.AddedDate) = 2017 group by convert(varchar(2), od.AddedDate, 101), UPC ) as sourcetable2 PIVOT( MAX(totalqty) FOR dateadded in([01],[02],[03],[04],[05],[06],[07],[08],[09],[10],[11],[12]) ) as p
Query Tables
select * from sys.tables order by modify_date desc
Toggle Identity Insert
SET IDENTITY_INSERT TableName ON -- insert ... SET IDENTITY_INSERT TableName OFF
Replace a char code with anything you want
REPLACE(value,CHAR(0233),'e')
Mass replace characters
update t set t.field = replace(t.field, b.Letter, b.ReplaceWithLetter) from table t inner join ACIIRef b on (t.field like '%' + b.Letter + '%')