Skip to content

Instantly share code, notes, and snippets.

@FlameWert
FlameWert / FindTextOccurrence
Created January 9, 2023 17:19
Find text occurrence in SQL Server
DECLARE @tosearch VARCHAR(MAX)='In'
SELECT (DATALENGTH(@string)-DATALENGTH(REPLACE(@string,@tosearch,'')))/DATALENGTH(@tosearch)
AS OccurrenceCount
#Add a snippet below in settins.json
{
"python.pythonPath": "Z:\\Projects\\Python\\ProjectName\\virtual_environment_name\\Scripts"
}
#It must have double backslashes, otherwise won't work.
@FlameWert
FlameWert / MutlipleConfigurations
Created January 5, 2023 05:04
Multiple configurations on launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Main File",
"type": "python",
"request": "launch",
@FlameWert
FlameWert / 2DateRanges
Created June 8, 2022 22:37
Join two tables with date ranges
-- Create schema
CREATE SCHEMA Experiment;
-- Create first table
CREATE TABLE [Experiment].[DateRange1](
[EmployeeID] [INT] NULL,
[Name] [VARCHAR](50) NULL,
[StartDate] [DATETIME] NULL,
[EndDate] [DATETIME] NULL
) ON [PRIMARY]
@FlameWert
FlameWert / RowCountPerTable.txt
Created April 6, 2022 16:45
Get row counts per table - SQL Server
SELECT
t.name AS TableName,
i.name as indexName,
sum(p.rows) as RowCounts,
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
@FlameWert
FlameWert / Merge overlapping date ranges
Last active December 15, 2021 03:46
Merge Overlapping Date Ranges in SQL Server
DECLARE @T table (GroupSourceID varchar(100), EmployeeID VARCHAR(100), StartDate datetime, EndDate datetime);
insert into @T values
('Green', '1' , '2017-01-02 00:00' , '2017-03-28 00:10'),
('Green', '1' , '2017-05-14 23:50' , '2017-05-29 23:50'),
('Green', '1' , '2017-04-14 23:50' , '2018-05-29 23:50'),
('Yellow', '2' , '2017-05-18 00:00' , '2017-05-18 04:00'),
('Yellow', '2' , '2017-05-18 02:00' , '2017-05-18 03:00'),
('Yellow', '1' , '2017-05-18 02:00' , '2017-05-18 03:00'),
('Blue', '1', '2017-01-02 00:00' , '2017-01-17 15:50'),
('Blue', '1', '2017-01-12 00:00' , '2017-02-17 15:50'),

Propagate non NULL values Up and Down in SQL Server.

  1. Create table
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@FlameWert
FlameWert / PY0101EN-5.2_API_2.ipynb
Created February 11, 2020 07:47
Created on Cognitive Class Labs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@FlameWert
FlameWert / PY0101EN-5.1_Intro_API.ipynb
Created February 11, 2020 07:21
Created on Cognitive Class Labs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@FlameWert
FlameWert / PY0101EN-5-2-Numpy2D.ipynb
Created February 10, 2020 18:53
Created on Cognitive Class Labs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.