<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jeremy Carroll on Medium]]></title>
        <description><![CDATA[Stories by Jeremy Carroll on Medium]]></description>
        <link>https://medium.com/@jeremycarroll77?source=rss-ffc395f74d98------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5zrlLHar2xQldDfO.</url>
            <title>Stories by Jeremy Carroll on Medium</title>
            <link>https://medium.com/@jeremycarroll77?source=rss-ffc395f74d98------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:11:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jeremycarroll77/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TSQL: find the highest paid employee per location and find min, max, and avg salary per location]]></title>
            <link>https://medium.com/@jeremycarroll77/i-got-this-problem-in-a-white-boarding-session-today-9e185c15c6ec?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e185c15c6ec</guid>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[t-sql]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 04:35:36 GMT</pubDate>
            <atom:updated>2024-04-11T05:57:06.296Z</atom:updated>
            <content:encoded><![CDATA[<p>I got this problem in a white boarding session today. I first devised the example using ROW_NUMBER(), but that causes both a hash join and a sort. Using the correlated subquery version improved the execution plan considerably. I’m sure there are other ways to skin this cat, but I didn’t want to create additional temporary objects, so I went with the CTE approach. Version 3 is the fastest on my machine.</p><pre>-- Departments<br>DROP TABLE IF EXISTS #Department;<br>CREATE TABLE #Department <br>(<br>   DepartmentID   INT<br> , DepartmentName VARCHAR(50)<br>);<br><br>-- Locations<br>DROP TABLE IF EXISTS #Location;<br>CREATE TABLE #Location <br>(<br>   LocationID   INT<br> , LocationName VARCHAR(50)<br>);<br><br>-- Employees<br>DROP TABLE IF EXISTS #Employee;<br>CREATE TABLE #Employee <br>(<br>   EmployeeID   INT<br> , FirstName    VARCHAR(50)<br> , LastName     VARCHAR(50)<br> , Age          INT<br> , Salary       DECIMAL(10, 2)<br> , DepartmentID INT<br> , LocationID   INT<br> , JobTitle     VARCHAR(50)<br>);<br><br>-- Customers<br>DROP TABLE IF EXISTS #Customer;<br>CREATE TABLE #Customer <br>(<br>   CustomerID   INT<br> , CustomerName   VARCHAR(50)<br> , City     VARCHAR(50)<br> , [State]    CHAR(2)<br> , AVGYearlyOrderTotal BIGINT<br>);<br><br><br>INSERT INTO #Department (DepartmentID, DepartmentName) <br>VALUES<br>(1, &#39;Human Sacrifice&#39;),<br>(2, &#39;Misdirection&#39;),<br>(3, &#39;Things that Move&#39;);<br>GO<br><br><br>INSERT INTO #Location (LocationID, LocationName) <br>VALUES<br>(1, &#39;Moscow&#39;),<br>(2, &#39;Vladimir&#39;),<br>(3, &#39;Pokrov&#39;);<br>GO<br><br>INSERT INTO #Employee (EmployeeID, FirstName, LastName, Age, Salary, DepartmentID, LocationID, JobTitle) <br>VALUES<br>(1, &#39;John&#39;, &#39;Doe&#39;, 34, 50000.00, 1, 1, &#39;Software Engineer&#39;),<br>(2, &#39;Jane&#39;, &#39;Smith&#39;, 29, 60000.00, 1, 2, &#39;Project Manager&#39;),<br>(3, &#39;Jim&#39;, &#39;Brown&#39;, 45, 55000.00, 2, 1, &#39;HR Specialist&#39;),<br>(4, &#39;Jake&#39;, &#39;Davis&#39;, 42, 62000.00, 3, 3, &#39;Marketing Director&#39;),<br>(5, &#39;Jill&#39;, &#39;Wilson&#39;, 38, 53000.00, 1, 1, &#39;Data Analyst&#39;),<br>(6, &#39;Joan&#39;, &#39;Moore&#39;, 47, 51000.00, 2, 2, &#39;Product Manager&#39;),<br>(7, &#39;Jeff&#39;, &#39;Taylor&#39;, 44, 49000.00, 1, 3, &#39;Software Engineer&#39;),<br>(8, &#39;Janet&#39;, &#39;Anderson&#39;, 41, 47000.00, 3, 1, &#39;Graphic Designer&#39;),<br>(9, &#39;Jerry&#39;, &#39;Thomas&#39;, 48, 58000.00, 2, 2, &#39;HR Manager&#39;),<br>(10, &#39;Joyce&#39;, &#39;Jackson&#39;, 39, 54000.00, 3, NULL, &#39;Sales Representative&#39;),<br>(11, &#39;Alice&#39;, &#39;Martin&#39;, 30, 52000.00, 1, 1, &#39;Software Engineer&#39;),<br>(12, &#39;Bob&#39;, &#39;Lewis&#39;, 32, 56000.00, 1, 2, &#39;Project Manager&#39;),<br>(13, &#39;Charlie&#39;, &#39;Clark&#39;, 28, 58000.00, 2, 3, &#39;HR Specialist&#39;),<br>(14, &#39;Diana&#39;, &#39;Walker&#39;, 41, 60000.00, 3, 1, &#39;Marketing Director&#39;),<br>(15, &#39;Evan&#39;, &#39;Hall&#39;, 37, 49000.00, 1, NULL, &#39;Data Analyst&#39;),<br>(16, &#39;Liam&#39;, &#39;Nelson&#39;, 33, 68000.00, 1, 1, &#39;Network Engineer&#39;),<br>(17, &#39;Olivia&#39;, &#39;Wright&#39;, 40, 72000.00, 2, 2, &#39;HR Manager&#39;),<br>(18, &#39;Noah&#39;, &#39;Carter&#39;, 29, 71000.00, 1, 3, &#39;Software Developer&#39;),<br>(19, &#39;Emma&#39;, &#39;Murphy&#39;, 43, 100500.00, 3, 1, &#39;Brand Manager&#39;),<br>(20, &#39;Ava&#39;, &#39;Powell&#39;, 31, 65000.00, 1, 2, &#39;UI/UX Designer&#39;),<br>(21, &#39;William&#39;, &#39;Reynolds&#39;, 38, 64000.00, 2, 3, &#39;Recruiter&#39;),<br>(22, &#39;Sophia&#39;, &#39;Perry&#39;, 27, 62000.00, 3, 1, &#39;Content Strategist&#39;),<br>(23, &#39;James&#39;, &#39;Brooks&#39;, 35, 210000.00, 1, 2, &#39;Cloud Architect&#39;),<br>(24, &#39;Isabella&#39;, &#39;Fisher&#39;, 42, 56000.00, 2, 3, &#39;Compensation Analyst&#39;),<br>(25, &#39;Benjamin&#39;, &#39;Gray&#39;, 30, 54000.00, 3, 1, &#39;Sales Executive&#39;);<br>GO<br><br><br>INSERT INTO #Customer (CustomerID, CustomerName, City, [State], AVGYearlyOrderTotal)<br>VALUES<br>(95,&#39;Michael Scott Paper Company&#39;, &#39;Scranton&#39; , &#39;PA&#39;, 9986000),<br>(100,&#39;Fuzzy Dice Mechanics&#39;, &#39;New Frisco&#39; , &#39;AK&#39;, 300750),<br>(101,&#39;Stay-Puft Marshmallow Crafters&#39;, &#39;New York&#39; , &#39;NY&#39;, 2162452368),<br>(102,&#39;Abnormal Adolescent Tortoise Martial Artists&#39;, &#39;New York&#39; , &#39;NY&#39;, 19882000),<br>(103,&#39;Cutting Edge Nerdy Technologists&#39;, &#39;Benjamin&#39; , &#39;CT&#39;, 550250),<br>(104,&#39;DatAnalytic&#39;, &#39;Boise&#39; , &#39;ID&#39;, 40000000),<br>(105,&#39;Techno Global Research Industries&#39;, &#39;Atlanta&#39; , &#39;GA&#39;, 2750800),<br>(106,&#39;Multivector Supply&#39;, &#39;Memphis&#39; , &#39;TN&#39;, 4375000),<br>(107,&#39;VIP Advertising&#39;, &#39;Chicago&#39; , &#39;IL&#39;, 1838014500),<br>(110,&#39;TenTex&#39;, &#39;Fort Lauderdale&#39; , &#39;FL&#39;, 872594300);<br>GO<br><br>/*<br>Write a SQL query to find the highest paid employee per location and find the minimum, <br>maximum and average salary at that location.  <br><br>Output:<br>A result set with columns:<br>DepartmentName, Location, JobTitle, EmployeeName (Concatenate First and Last Name), Salary, AVGSalary, MINSalary and MAXSalary<br>*/<br><br>-- Version 1<br>WITH highest_paid_emp_per_location <br>AS <br>(<br>    SELECT <br>          e.EmployeeID<br>        , e.FirstName<br>        , e.LastName<br>        , e.Salary<br>  , e.JobTitle<br>  , d.DepartmentName<br>        , COALESCE(e.LocationID , -1) AS LocationID<br>        , ROW_NUMBER() OVER (PARTITION BY COALESCE(e.LocationID, -1) ORDER BY e.Salary DESC) AS rnk<br>    FROM <br>        #Employee    AS e<br>  LEFT JOIN #Department AS d<br>   ON e.DepartmentID = d.DepartmentID<br>),<br>top_paid_emps AS<br>(<br> SELECT <br>    cte.DepartmentName<br>  , COALESCE(l.LocationName , &#39;No Location Name&#39;) AS LocationName<br>  , cte.JobTitle<br>  , COALESCE(cte.FirstName , &#39;No First Name&#39;) + &#39; &#39; + COALESCE(cte.LastName , &#39;No Last Name&#39;) AS EmployeeName<br>  , cte.Salary<br>  , cte.LocationID<br> FROM highest_paid_emp_per_location  AS cte<br>  LEFT JOIN #Location    AS l <br>   ON cte.LocationID = COALESCE(l.LocationID, -1)<br> WHERE <br>  cte.rnk = 1<br>)<br>SELECT <br>   tpe.DepartmentName<br> , tpe.LocationName<br> , tpe.JobTitle<br> , tpe.EmployeeName<br> , tpe.Salary<br> , salary_stats.MINSalary<br> , salary_stats.MAXSalary<br> , salary_stats.AVGSalary<br>FROM top_paid_emps AS tpe<br> INNER JOIN <br>  (<br>   SELECT <br>      COALESCE(l.LocationID , -1) AS LocationID<br>    , MIN(e.Salary)      AS MINSalary<br>    , MAX(e.Salary)      AS MAXSalary<br>    , AVG(e.Salary)      AS AVGSalary<br>   FROM #Employee    AS e<br>    LEFT JOIN #Location  AS l<br>     ON e.LocationID = l.LocationID<br>    LEFT JOIN #Department AS d<br>     ON e.DepartmentID = d.DepartmentID<br>   GROUP BY <br>      l.LocationID<br>  ) AS salary_stats<br>  ON tpe.LocationID = salary_stats.LocationID;<br><br>-- Version 2 (eliminated hash join and sort operators)<br>WITH top_paid_emps AS<br>(<br>    SELECT <br>          e.EmployeeID<br>        , e.FirstName<br>        , e.LastName<br>        , e.Salary<br>        , e.JobTitle<br>        , d.DepartmentName<br>        , COALESCE(e.LocationID, -1) AS LocationID<br>    FROM #Employee   AS e<br>    LEFT JOIN #Department AS d <br>  ON e.DepartmentID = d.DepartmentID<br>),<br>highest_paid_per_location AS<br>(<br>    SELECT <br>          te.*<br>    FROM <br>        top_paid_emps AS te<br>    WHERE <br>        NOT EXISTS (<br>            SELECT 1 <br>            FROM top_paid_emps AS te2 <br>            WHERE te2.LocationID = te.LocationID <br>    AND te2.Salary &gt; te.Salary<br>        )<br>)<br>SELECT <br>      hpl.DepartmentName<br>    , COALESCE(l.LocationName, &#39;No Location Name&#39;) AS LocationName<br>    , hpl.JobTitle<br>    , COALESCE(hpl.FirstName, &#39;No First Name&#39;) + &#39; &#39; + COALESCE(hpl.LastName, &#39;No Last Name&#39;) AS EmployeeName<br>    , hpl.Salary<br>    , agg_data.MINSalary<br>    , agg_data.MAXSalary<br>    , agg_data.AVGSalary<br>FROM <br>    highest_paid_per_location AS hpl<br> LEFT JOIN #Location   AS l <br>  ON hpl.LocationID = l.LocationID<br> LEFT JOIN <br>  (<br>   SELECT <br>      LocationID<br>    , MIN(Salary) AS MINSalary<br>    , MAX(Salary) AS MAXSalary<br>    , AVG(Salary) AS AVGSalary<br>   FROM <br>    top_paid_emps<br>   GROUP BY <br>    LocationID<br>  ) AS agg_data <br>  ON hpl.LocationID = agg_data.LocationID;<br><br>-- Version 3<br>WITH highest_paid_emp_per_location AS <br>(<br>    SELECT <br>            e.EmployeeID<br>          , e.FirstName<br>          , e.LastName<br>          , e.Salary<br>          , e.JobTitle<br>          , d.DepartmentName<br>          , l.LocationName<br>          , RANK() OVER (PARTITION BY COALESCE(e.LocationID, -1) ORDER BY e.Salary DESC)    AS rnk<br>          , MIN(e.Salary) OVER (PARTITION BY COALESCE(e.LocationID, -1))     AS MINSalary<br>          , MAX(e.Salary) OVER (PARTITION BY COALESCE(e.LocationID, -1))     AS MAXSalary<br>          , AVG(e.Salary) OVER (PARTITION BY COALESCE(e.LocationID, -1))     AS AVGSalary<br>    FROM <br>        #Employee   AS e<br>    LEFT JOIN #Department AS d <br>  ON e.DepartmentID = d.DepartmentID<br>    LEFT JOIN #Location  AS l <br>  ON e.LocationID = l.LocationID<br>)<br>SELECT <br>        DepartmentName<br>      , COALESCE(LocationName , &#39;No Location Name&#39;) AS LocationName<br>      , JobTitle<br>      , CONCAT(FirstName, &#39; &#39;, LastName) AS EmployeeName<br>      , Salary<br>      , MINSalary<br>      , MAXSalary<br>      , AVGSalary<br>FROM <br>    highest_paid_emp_per_location<br>WHERE <br>    rnk = 1;<br><br>DROP TABLE IF EXISTS #Department;<br>DROP TABLE IF EXISTS #Location;<br>DROP TABLE IF EXISTS #Employee;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e185c15c6ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TSQL — Calculate Previous Year Revenue and YoY Revenue Change Using LAG()]]></title>
            <link>https://medium.com/@jeremycarroll77/tsql-calculate-previous-year-revenue-and-yoy-revenue-change-using-lag-fe5fe1922a68?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe5fe1922a68</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[t-sql]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 18:43:22 GMT</pubDate>
            <atom:updated>2024-04-03T18:43:22.457Z</atom:updated>
            <content:encoded><![CDATA[<h3>TSQL — Calculate Previous Year Revenue and YoY Revenue Change Using LAG()</h3><p>I got this one dumped on me sight unseen in a white-boarding session. In a hurry, I used YEAR() in the WHERE clause and tried using SUM() in the GROUP BY. My heart was in the right place, my brain two cups of coffee shy of sentience. The first use of LAG() looks a little bit wordy; so, I went with a common table expression in version 2. I’m sure ChatGPT has its own confabulations. These are mine.</p><pre>USE AdventureWorks2019;<br>GO<br><br>/*****************************************************/<br>/* Get Total Revenue by Product for TotalUnits &gt; 500 */<br>/* Make the WHERE clause SARGable                    */<br>/*****************************************************/<br>SELECT <br>   p.[Name]  <br> , SUM(sod.OrderQty)     AS TotalUnits<br> , SUM(sod.UnitPrice * sod.OrderQty) AS TotalRevenue<br>FROM Sales.SalesOrderHeader    AS soh<br> INNER JOIN Sales.SalesOrderDetail AS sod<br>  ON soh.SalesOrderID = sod.SalesOrderID<br> INNER JOIN Production.Product  AS p<br>  ON sod.ProductID = p.ProductID<br>WHERE <br> OrderDate &gt;= &#39;01-01-2011&#39; <br> AND OrderDate &lt; &#39;01-01-2012&#39;<br>GROUP BY <br> p.[Name]<br>HAVING <br> SUM(sod.OrderQty) &gt; 500;<br><br><br>/****************************************************************/<br>/* Get Current Year Revenue, Previous Year Revenue, and the YoY */<br>/* Revenue Change by Product and Year for TotalUnits &gt; 500      */<br>/****************************************************************/<br>/**** VERSION 1 ****/<br>SELECT <br>   p.[Name] <br> , YEAR(soh.OrderDate)      AS [Year]<br> , SUM(sod.OrderQty)       AS TotalUnits<br> , SUM(sod.UnitPrice * sod.OrderQty)   AS CurrentYearRevenue<br> , LAG(SUM(sod.UnitPrice * sod.OrderQty)) <br>  OVER (<br>    ORDER BY p.[Name] , YEAR(soh.OrderDate) <br>       )         AS PreviousYearRevenue<br> , SUM(sod.UnitPrice * sod.OrderQty) <br>  - LAG(SUM(sod.UnitPrice * sod.OrderQty)) <br>  OVER (<br>    ORDER BY p.[Name] , YEAR(soh.OrderDate) <br>       )         AS ChangeInYoYRevenue<br>FROM Sales.SalesOrderHeader    AS soh<br> INNER JOIN Sales.SalesOrderDetail AS sod<br>  ON soh.SalesOrderID = sod.SalesOrderID<br> INNER JOIN Production.Product  AS p<br>  ON sod.ProductID = p.ProductID<br>WHERE <br> OrderDate &gt;= &#39;01-01-2011&#39; <br> AND OrderDate &lt; &#39;01-01-2013&#39;<br>GROUP BY <br>   p.[Name]<br> , YEAR(soh.OrderDate)<br>HAVING <br> SUM(sod.OrderQty) &gt; 500<br>ORDER BY<br>   p.[Name]<br> , [Year];<br><br>/**** VERSION 2 ****/<br>WITH YearlyRevenue AS (<br>SELECT <br>    p.[Name],<br>    YEAR(soh.OrderDate) AS [Year],<br>    SUM(sod.UnitPrice * sod.OrderQty) AS CurrentYearRevenue<br>FROM <br>    Sales.SalesOrderHeader AS soh<br>    INNER JOIN Sales.SalesOrderDetail AS sod ON soh.SalesOrderID = sod.SalesOrderID<br>    INNER JOIN Production.Product AS p ON sod.ProductID = p.ProductID<br>WHERE <br>    soh.OrderDate &gt;= &#39;01-01-2011&#39; AND soh.OrderDate &lt; &#39;01-01-2013&#39;<br>GROUP BY <br>    p.[Name], YEAR(soh.OrderDate)<br>HAVING <br>    SUM(sod.OrderQty) &gt; 500<br>)<br>SELECT <br>    *,<br>    LAG(CurrentYearRevenue) OVER (ORDER BY [Name] , [Year]) AS PreviousYearRevenue,<br>    CurrentYearRevenue - LAG(CurrentYearRevenue) OVER (ORDER BY [Name] , [Year]) AS ChangeInYoYRevenue<br>FROM <br>    YearlyRevenue<br>ORDER BY <br>    [Name], [Year];</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe5fe1922a68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TSQL — Calculate Bonus and Update Salary — Row vs. Set-Based Operation]]></title>
            <link>https://medium.com/@jeremycarroll77/tsql-calculate-bonus-and-update-salary-row-vs-set-based-operation-e9d2bf8f7733?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9d2bf8f7733</guid>
            <category><![CDATA[rbar]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[t-sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 18:30:53 GMT</pubDate>
            <atom:updated>2024-04-03T18:30:53.061Z</atom:updated>
            <content:encoded><![CDATA[<h3>TSQL — Calculate Bonus and Update Salary — Row vs. Set-Based Operation</h3><p>I was asked to write a row-based loop to update salaries after calculating a bonus. This isn’t rocket science, but it worth demonstrating a single set-based approach versus the RBAR habits of most full-stack engineers with the inertia of their imperative language style.</p><pre>/************************************/<br>/*  Row-Based Solution      */<br>/************************************/<br>DROP TABLE IF EXISTS dbo.employees;<br>CREATE TABLE dbo.employees<br>(<br>   id  TINYINT   NOT NULL IDENTITY PRIMARY KEY<br> , [name] CHAR(1)   NOT NULL<br> , salary NUMERIC(8,2) NULL<br> , bonus NUMERIC(8,2) NULL DEFAULT(0)<br>);<br>GO<br><br>INSERT INTO dbo.employees ([name] , salary)<br> VALUES(&#39;A&#39; , 50000) , (&#39;B&#39; , 100000) , (&#39;C&#39; , NULL);<br><br>--SELECT * FROM dbo.employees;<br>--GO<br>DECLARE <br>   @max_id     INT = 0 <br> , @current_id INT = 0;<br><br>SELECT <br>   @current_id = MIN(id) <br> , @max_id  = MAX(id) <br>FROM dbo.employees;<br><br>SET STATISTICS IO, TIME ON;<br>-- LOOP for each Id set bonus<br>WHILE (@current_id &lt;= @max_id)<br> BEGIN<br>  UPDATE dbo.employees<br>  SET bonus = <br>    CASE <br>     WHEN salary &lt;  50000       THEN salary * 0.05<br>     WHEN salary &lt;= 50000 AND salary &lt; 100000  THEN salary * 0.07<br>     WHEN salary &gt;= 100000       THEN salary * 0.10<br>     ELSE 0 <br>    END,<br>   salary = <br>    CASE <br>     WHEN salary &lt;  50000       THEN salary * 1.05<br>     WHEN salary &lt;= 50000 AND salary &lt; 100000  THEN salary * 1.07<br>     WHEN salary &gt;= 100000       THEN salary * 1.10<br>     ELSE 0 <br>    END<br>   WHERE id = @current_id;<br>   <br>  SET @current_id += 1;<br> END;<br>SET STATISTICS IO, TIME OFF;<br><br>--SELECT * FROM dbo.employees;<br>GO<br><br>/************************************/<br>/*  Set-Based Solution      */<br>/************************************/<br>DROP TABLE IF EXISTS dbo.employees;<br>CREATE TABLE dbo.employees<br>(<br>   id  TINYINT   NOT NULL IDENTITY PRIMARY KEY<br> , [name] CHAR(1)   NOT NULL<br> , salary NUMERIC(8,2) NULL<br> , bonus NUMERIC(8,2) NULL DEFAULT(0)<br>);<br>GO<br><br>INSERT INTO dbo.employees ([name] , salary)<br> VALUES(&#39;A&#39; , 50000) , (&#39;B&#39; , 100000) , (&#39;C&#39; , NULL);<br><br>--SELECT * FROM dbo.employees;<br>--GO<br><br>SET STATISTICS IO, TIME ON;<br>UPDATE dbo.employees<br>SET bonus = <br>  CASE <br>   WHEN salary &lt;  50000       THEN salary * 0.05<br>   WHEN salary &lt;= 50000 AND salary &lt; 100000  THEN salary * 0.07<br>   WHEN salary &gt;= 100000       THEN salary * 0.10<br>   ELSE 0 <br>  END,<br> salary = <br>  CASE <br>   WHEN salary &lt;  50000       THEN salary * 1.05<br>   WHEN salary &lt;= 50000 AND salary &lt; 100000  THEN salary * 1.07<br>   WHEN salary &gt;= 100000       THEN salary * 1.10<br>   ELSE 0 <br>  END;<br>SET STATISTICS IO, TIME OFF;<br><br>--SELECT * FROM dbo.employees;<br>--GO</pre><p>I ought to show the clustered index update execution plan, but we can guess that the row-based update will take as many update executions as rows in the original table, and the set-based solution will update the index all at once in one operation. Think in sets. It saves the sanity of DBAs everywhere.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9d2bf8f7733" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Awakening From the Meaning Crisis — Part 2 — Flow, Metaphor, Axial Revolution — John Vervaeke —…]]></title>
            <link>https://medium.com/@jeremycarroll77/awakening-from-the-meaning-crisis-part-2-flow-metaphor-axial-revolution-john-vervaeke-de3c514298cb?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/de3c514298cb</guid>
            <category><![CDATA[meaning-of-life]]></category>
            <category><![CDATA[meaningful-life]]></category>
            <category><![CDATA[meaninglessness]]></category>
            <category><![CDATA[john-vervaeke]]></category>
            <category><![CDATA[meaning]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 19:49:25 GMT</pubDate>
            <atom:updated>2024-04-02T19:49:25.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>Awakening From the Meaning Crisis — Part 2 — Flow, Metaphor, Axial Revolution — John Vervaeke — Notes</h3><p>Books –</p><p>· “Flow” — Mihaly Csikszentmihalyi (1990)</p><p>· “Implicit Learning and Tacit Knowledge” — Arthur S. Reber</p><p>· “Educating Intuition” — Robin M. Hogarth</p><p>· “Mind, Reason, and Being in the World” — Joe Schear</p><p>· “The Better Angels of Our Nature” — Steven Pinker</p><p>· “Metaphysics We Live By” — ?</p><p>· “The Origin and Goal of History” — K. Jaspers</p><p>· “The Great Transformation” — Karen Armstrong</p><p>· “The End of the Bronze Age” — Robert Drews</p><p>· “1177 B.C. — The Year Civilization Collapsed” — Eric Cline</p><p>· “The Axial Age and Its Consequences” — R. Bellah</p><p>Notes:</p><p>· The flow channel cuts through anxiety and boredom</p><p>· Skills &gt; Demands -&gt; boring</p><p>· Skills &lt; Demands -&gt; anxiety</p><p>· Flow Induction Technology: (1) Tight feedback from the environment; (2) Clear information; (3) Failure matters (video games, rock climbing, martial arts, jazz, a hockey goalie)</p><p>· Flow does not equal pleasure = meaning in life</p><p>· The flow state is a human universal and is important in cognitive science. Gives insight into the brain and mind. In it, the self is decreased, one is more spontaneous, and time moves differently</p><p>· Insight Cascade: “Aha!” — Frame -&gt; Break Frame -&gt; Reframe -&gt; … repeat</p><p>· Game: s1 = xyz, s2 = yza, s3 = oox, s4 = ooy, s = oob…find a pattern. S3 = VowelVowelConsonant. How did you know that? What looks like psychic insight is just you picking up implicitly on patterns in your environment. Is Déjà vu just pattern recognition?</p><p>· Intuition is real, but it is not magic. It is a result of implicit learning.</p><p>· You know how far to stand from someone. You don’t kiss the King of England or pt your hand on his shoulder. You know how far to stand from the casket when it is empty or there lies a dead man’s body. How did you know this?</p><p>· Bias and Prejudice = bad intuition. Black dude robbed a neighbor. All black folks are thieves. If you believe this from watching it on TV news, then you are a useful idiot who has bullshitted themselves. A helicopter crashes in Magadan, Russia means the Russian Federation’s air force is total garbage said Euromaidan News. Should you take this as fact? Beware of propaganda!</p><p>· Beware of correlational vs. causal patterns</p><p>· Get into the flow state to see casual patterns better. This is what happened during the Upper Paleolithic Transition period.</p><p>· Metaphor: project- reflect — subject — do you understand? — see my point?</p><p>· Altered states of consciousness in the brain (DMT, peyote, ketamine, MDMA, etc.) happens when areas of the brain, that do not normally communicate, start connecting. The increase in causal pattern recognition means an increase in good intuition and increased metaphor generation.</p><p>· “Use an analogy” –&gt; use a metaphor. People, who are better at generating analogies, are better at life.</p><p>· Shaman’s experience “soul flight” — flying above the world — “getting high” — “getting a bigger picture” — “over-sight” — “supervision” — “supernatural” — “top-down” — “God’s-eye view” — “transcendence” — think of Walker Percy’s “The Last Self-Help Book” and Einstein’s going into orbit. What goes up must come down.</p><p>· 10,000 BCE — agriculture — saty in one place in a complex society. Stone gives wa to metal — BRONZE AGE — Eqypt (gov’t…got to wrangle the farmers to store crops so we don’t starve), Mesopotamia</p><p>· 3,300 BCE — 1,177 BCE (1,300–1,100) Bronze Age…don’t get hung-up on dates.</p><p>· Bronze = tin + copper or arsenic + copper if you are up for it… (<a href="https://youtu.be/M4LRHJlijVU?si=JmnznkOOdZK26MbU">https://youtu.be/M4LRHJlijVU?si=JmnznkOOdZK26MbU</a>)</p><p>· Cyprus — “Copper”</p><p>· Megiddo — Bronze Age city — Greek name = Armageddon</p><p>· Have you read any tales from the Bronze Age? Any Egyptian mythology? No, you have not! Why? You read the Bible, Buddha, Tao, Confucius, Socrates, Plato, Pythagoras, Jesus. Why? What changed?</p><p>· The Axial Revolution — the Bronze Age collapses. This is the greatest collapse the world has ever experienced. More cities and cultures disappear than at any time in all human history (as of 2024). Almost total apocalypse.</p><p>· 1,177 BCE -…- 800 BCE — in between we had a Dark Age</p><p>· We lost all astronomy and medicine.</p><p>· Little small-scale societies pop up. A new pressure on human cognition arises. They create new psychotechnology. A new kind of literacy arises. Cuneiform and Hieroglyphics existed before 1,177 BCE. A scribe (scribble, scrabble) was a full-time job. 1% of people could “read”. What was the “inner dialogue” of 99% of people who could neither read nor write? Literacy is hard when writing is ideographic. The Dark Age bring alphabetic literacy. Canaanite -&gt; Phoenician -&gt; Greece</p><p>· This new literacy is much easier to learn. I become more aware of my own thoughts. I can correct my thinking independently of my mind. Write it down and fix it.</p><p>· 2nd-Order Thinking: internalize literacy into your metacognition improving your ability to examine and correct your own thinking. Think about your thinking.</p><p>· Metacognition: knowledge of your own thinking</p><p>· Mobile armies arrived in the Dark Age. Coinage appears. Money was physical. How many seashells or virgins do you have? Money is, in fact, just an abstraction. We begin using numeracy to think mathematically.</p><p>· Now, people can transcend themselves and it enhances their awareness of their own self-deception (self-bullshitting). People start to realize a personal sense of responsibility. Oh no, here comes sin, vice, virtue, and morality! Morality begins 800 years before Jesus pops up. Desert religions…the edge of the desert…”Ahh!”…the universe is so dark, black, cold, and empty…”Ahh!” (Pascal’s Terror)</p><p>· Psychotechnology: alphabetic literacy, numeracy, mathematical thinking (1,2,3,…aleph naught)…”Ahh, again!”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de3c514298cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Awakening from the Meaning Crisis — Part 1 — Introduction — John Vervaeke — My Notes]]></title>
            <link>https://medium.com/@jeremycarroll77/awakening-from-the-meaning-crisis-part-1-introduction-john-vervaeke-my-notes-c79b3f13784a?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/c79b3f13784a</guid>
            <category><![CDATA[meaningful-life]]></category>
            <category><![CDATA[meaninglessness]]></category>
            <category><![CDATA[insights]]></category>
            <category><![CDATA[john-vervaeke]]></category>
            <category><![CDATA[meaning]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 19:00:13 GMT</pubDate>
            <atom:updated>2024-04-02T19:00:13.654Z</atom:updated>
            <content:encoded><![CDATA[<h3>Awakening from the Meaning Crisis — Part 1 — Introduction — John Vervaeke — My Notes</h3><p>Books:</p><p>· “The Scientific Study of Personal Wisdom” — Michel Ferrari</p><p>· “How to be a Stoic” — Massimo Pigliucci</p><p>· “Meaning in Life and Why It Matters” — Susan Wolf</p><p>· “On Bullshit” — Harry Frankfurt</p><p>· “Supernatural Selection” — Matt Rosano</p><p>· “Mindsight” — Daniel J. Siegel M.D.</p><p>· “After Phrenology” — Michael L. Anderson</p><p>· “Natural-Born Cyborg” — Andy Clark</p><p>· “Shamanism” — Mircea Eliade and Wendy Doniger</p><p>· “Waking From Sleep” — Steve Taylor</p><p>· “The Mind in the Cave” — David Lewis-Williams</p><p>Notes:</p><p>· I can’t be unbiased. That’s not a thing.</p><p>· Get out of your virtual environments.</p><p>· Why is crisis and collapse a looming concern?</p><p>· Why do we hunger for meaning?</p><p>· Wisdom is all about meaning in life.</p><p>· To know does not equal belief or ideology (propositional knowledge)</p><p>· Procedural Knowing — knowing how</p><p>· Perspectival Knowing — what it is like</p><p>o “How are you?” is a perspective-taking ritual. The self is built this way.</p><p>· Participatory Knowing — to be in relationship</p><p>· PROJECT, OBEJECT, SUBJECT — all day long you are throwing</p><p>· 40,000 BCE Upper Paleolithic Transition ~200,000 BCE we humans arrived</p><p>· Art, sculpture, music, cave paintings, 1st calendars (no numbers or dates…uses moon patterns), thin shaft projectile weapons with good blades</p><p>· 60,000–70,000 BCE humans almost went extinct (less than 10,000 individuals remained) they moved to the coasts</p><p>· Humans created broader trading networks</p><p>· Initiation rituals are painful because pain shows commitment and you must regulate your emotion by de-centering, i.e., allow yourself to be put in other people’s hands</p><p>o You learn empathy.</p><p>· Exaptation — tongues did not evolve for speech. The cognitive biases and heuristics which make you highly adaptive also make you highly receptive to bullshit, e.g., political propaganda, advertising, biases news, alcoholism, anxiety, pills, depression, etc.</p><p>· Shamanic rituals arise. The best healthcare for a very long time. This is the software change to the brain (~40,000 BCE)</p><p>· Think outside the box. The 9-dot problem. One must reframe problems. Disrupt your framing to gain insight. Use four and only four lines to connect the dots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/130/1*Ijb-PA2a3sv7k_eaJ0SUfw.jpeg" /></figure><p>· Psycho-Technology — you brain integrates you with machines. You are wearing a shirt, shoes, a watch, standing at a desk in front of a whiteboard with a marker in hand, writing. You are the naked being. “Fits your brain” -&gt; literacy. I can network my brain over time and network with your brain. Think of taking notes, recording a message, making a video or podcast. You create your being extended in time.</p><p>· Shaman — sleep deprivation, hours of singing, sexual (hyper — ; none) dress like an animal, eat psychedelics, chanting, dancing</p><p>· Telling a person to “think outside the box” does not change their belief about the 9-dot problem. It does NOT help them solve it.</p><p>· Do not limit your knowledge to beliefs. Faith in beliefs is a ridiculous way to live. Plato thought his beliefs were probably right or wrong, but who the hell knows. Don’t put so much stock in your propositions. You need to know HOW to get outside the box. Shamanism is meant to reframe, to gain insight and mindsight.</p><p>· They trigger the placebo effect. 30–40% of modern medicine’s benefits come from this effect. No healthcare, but a dancing naked deer-man comes to your hut and gets you to believe you’ll get better. Take it or leave it.</p><p>· Shaman — one who knows, sees, has insight</p><p>· Wizard — wise person</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c79b3f13784a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IS (NOT) DISTINCT FROM vs ISNULL and COALESCE T-SQL 2022]]></title>
            <link>https://medium.com/@jeremycarroll77/is-not-distinct-from-vs-isnull-and-coalesce-t-sql-2022-3857ed48f20a?source=rss-ffc395f74d98------2</link>
            <guid isPermaLink="false">https://medium.com/p/3857ed48f20a</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[t-sql]]></category>
            <category><![CDATA[sql-server]]></category>
            <dc:creator><![CDATA[Jeremy Carroll]]></dc:creator>
            <pubDate>Wed, 06 Mar 2024 00:20:58 GMT</pubDate>
            <atom:updated>2024-03-06T00:20:58.595Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*N_Bgm7dS35vI3tB__rqDYQ.jpeg" /></figure><p>With ANSI_NULLS = ON by default, Column2 = NULL, for example, will always return an empty set. With ANSI_NULLS = OFF, Column2 = NULL will return rows 4 &amp; 5 as seen above.</p><pre>SET ANSI_NULLS ON;<br>GO<br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE Column2 = NULL;<br>GO</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*7NkfLgT7sGo2aFQnTwsLNw.jpeg" /><figcaption>ANSI_NULLS ON</figcaption></figure><pre>SET ANSI_NULLS OFF;<br>GO<br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE Column2 = NULL;<br>GO</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*xiijMpv1x0soZOacv1IrFg.jpeg" /><figcaption>ANSI_NULLS OFF</figcaption></figure><p>Assuming that ANSI NULLS will remain ON in most code, before SQL Server 2022, we had to wrap nullable columns with ISNULL() or COALESCE().</p><pre>SELECT *<br>FROM dbo.ExampleTable<br>WHERE ISNULL(Column1,0) &lt;&gt; ISNULL(Column2,0);<br><br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE COALESCE(Column1,0) &lt;&gt; COALESCE(Column2,0); <br>GO</pre><p>The only difference seems to be a case statement in the table scan operator where COALESCE() is used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*-3AvoJxJdobLKXT3s8zrSQ.jpeg" /><figcaption>COALESCE(Column) &lt;&gt; …</figcaption></figure><p>IS (NOT) DISTINCT FROM enables one to compare NULLs without relying on functions. On my simple table, all three comparison mechanisms take 33% of the batch and return identical results.</p><pre>SELECT *<br>FROM dbo.ExampleTable<br>WHERE Column1 IS DISTINCT FROM Column2;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*-3AvoJxJdobLKXT3s8zrSQ.jpeg" /><figcaption>IS DISTINCT FROM</figcaption></figure><p>The results using IS NOT DISTINCT FROM…</p><pre>-- Use IS NOT DISTINCT FROM-(IDENTICAL...DUPES)--like logic<br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE ISNULL(Column1,0) = ISNULL(Column2,0);<br><br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE COALESCE(Column1,0) = COALESCE(Column2,0);<br><br>SELECT *<br>FROM dbo.ExampleTable<br>WHERE Column1 IS NOT DISTINCT FROM Column2;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*hj6eRDX_GBmoVmudX_lpIg.jpeg" /><figcaption>IS NOT DISTINCT FROM</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*2jIGGrTwv-X9IM3BYG54gw.jpeg" /><figcaption>IS NULL PREDICATE FROM TABLE SCAN</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*ArG1XnP1rlUwwXg0PEoWCg.jpeg" /><figcaption>COALESCE PREDICATE FROM TABLE SCAN</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*rDb8ExAbjPfIh7E0qkh7Iw.jpeg" /><figcaption>IS NOT DISTINCT FROM TABLE SCAN</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3857ed48f20a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>