Skip to content

Instantly share code, notes, and snippets.

@thorsman99
thorsman99 / DataRowToXML.cs
Last active December 20, 2018 13:17
DataRow to XML #CSharp #function #conversion #XML
static string RowToXML(DataRow DRInput)
{
DataSet myDS = new DataSet();
myDS.Tables.Add(DRInput.Table.Clone());
myDS.Tables[0].ImportRow(DRInput);
return myDS.GetXml(); ;
}
@thorsman99
thorsman99 / InsertNotPresent.sql
Created May 29, 2018 08:12
Inserts only rows not found in destination #sql
Insert into [server].database.dbo.table
select src.* from table src
left join [server].database.dbo.table sta
ON sta.Key = src.Key
where sta.Key IS NULL
@thorsman99
thorsman99 / CurlForWindows.txt
Created February 26, 2018 17:35
Curl equivalent for Windows #Utility #curl
powershell -Command "(new-object net.webclient).DownloadString('https://api.ipdata.co')"
@thorsman99
thorsman99 / AvgTime.sql
Created January 26, 2018 18:54
Get average time between records #SQL
Select AVG(CAST(DATEDIFF(MINUTE,B.TimeStamp,A.TimeStamp) AS int)) AvgTime
from tblLoadPoint A
OUTER APPLY (SELECT TOP 1 *
FROM tblLoadPoint
Where TimeStamp < A.TimeStamp
Order By TimeStamp DESC) B
@thorsman99
thorsman99 / DTwithMS.sql
Created December 12, 2017 13:18
DateTime print with milliseconds #SQL
PRINT (CONVERT( VARCHAR(24), GETDATE(), 121))
@thorsman99
thorsman99 / CheckTable.sql
Created December 6, 2017 14:26
Check Existence of Table in DB #sql
IF OBJECT_ID(N'SqlHintsDemoDB.dbo.Customers', N'U') IS NOT NULL
BEGIN
PRINT 'Table Exists'
END
@thorsman99
thorsman99 / TempTableDrop.sql
Created November 29, 2017 12:44
Drop Temp Table if Exists #sql
IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
@thorsman99
thorsman99 / Tbl&ColList.sql
Created November 16, 2017 16:43
List sql tables and columns #sql
SELECT db_name() as DATABASE_NAME, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION,
COLUMN_DEFAULT, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION, NUMERIC_PRECISION_RADIX, NUMERIC_SCALE,
DATETIME_PRECISION
FROM INFORMATION_SCHEMA.COLUMNS
@thorsman99
thorsman99 / rebuildallindexes.sql
Created October 1, 2017 03:10
Rebuilds all sql indexes for a table #SQL
ALTER INDEX ALL ON Production.Product
REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON,
STATISTICS_NORECOMPUTE = ON);
@thorsman99
thorsman99 / ShowForeignKeys.sql
Created October 1, 2017 03:09
Shows all foreign keys related to a table. #SQL
EXEC sp_fkeys 'TableName' --Show all foreign key relationships