Skip to content

Instantly share code, notes, and snippets.

Cedric Bertolasio cbertolasio

Block or report user

Report or block cbertolasio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cbertolasio
cbertolasio / getSpidLastBatch.sql
Created Feb 15, 2018
gets the last sql command issued by a spid
View getSpidLastBatch.sql
sp_who2
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = 62
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
GO
@cbertolasio
cbertolasio / sql_table_rowCounts.sql
Created Feb 6, 2018
a way to get row counts and table size for a given sql db
View sql_table_rowCounts.sql
-- https://blog.sqlauthority.com/2017/05/25/sql-server-simple-query-list-size-table-row-counts/
USE [YourDBName] -- replace your dbname
GO
SELECT
s.Name AS SchemaName,
t.Name AS TableName,
p.rows AS RowCounts,
CAST(ROUND((SUM(a.used_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Used_MB,
CAST(ROUND((SUM(a.total_pages) - SUM(a.used_pages)) / 128.00, 2) AS NUMERIC(36, 2)) AS Unused_MB,
CAST(ROUND((SUM(a.total_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Total_MB
@cbertolasio
cbertolasio / dopTablesInBulk.sql
Created Feb 2, 2018
cursor to drop tables matching a given name in sql server
View dopTablesInBulk.sql
select name
from [tst-IrrigationReporting].sys.tables
where name like 'YourTableName_2018%'
-- and is_ms_shipped = 0;
DECLARE @cmd varchar(4000)
DECLARE cmds CURSOR FOR
SELECT 'drop table [' + Table_Name + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Name LIKE 'YourTableName_2018%'
@cbertolasio
cbertolasio / formatFilenameUsingDateTime.py
Created Jan 30, 2018
Format a string using datetime parts in python
View formatFilenameUsingDateTime.py
#assuming the date is 25-JAN-2018 at 01:30:52
#the code below shouldPrint "AllPivots_20180125_0130"
from datetime import datetime
current = datetime.utcnow()
print(current)
year = str(current.year)
month = str(current.month).zfill(2)
day = str(current.day).zfill(2)
hours = str(current.hour).zfill(2)
@cbertolasio
cbertolasio / DateTimeHelper.cs
Last active Oct 28, 2016
C# date time helper for parsing "date + time + timezone offset in minutes" into the date that "I" want... ## the basic premise is that... - the user will pick a date using a date picker - the user will pick a time using a time picker - the moment js library will calculate the users timezone offset in minutes - based on their current browser sett…
View DateTimeHelper.cs
public static class DateTimeHelper
{
public static DateTimeOffset Combine(DateTimeOffset? originalDate, string timeString, int timeZoneOffsetInMinutes)
{
if(originalDate.HasValue)
{
return FromString(GetDateAsString(originalDate.Value.Date, timeString, timeZoneOffsetInMinutes));
}
else
{
You can’t perform that action at this time.