Skip to content

Instantly share code, notes, and snippets.

View alexdwhite's full-sized avatar

Alex White alexdwhite

View GitHub Profile
@alexdwhite
alexdwhite / SQLTempTableLoop
Last active December 29, 2015 09:29
SQL Temp Table Loop
-- This can be performed numerous ways, and can also be performed more efficiently, but I broke out the
-- sections so that they are easy to identify and understand
-- create temp table
declare @tbl table (id int identity, valueA int)
-- used for the loop
declare @ptr int, @max int, @valueA int
-- insert list of ID's into temp table
@alexdwhite
alexdwhite / Sample SQL Update with Join statement
Created March 18, 2018 01:23
I wrote a joined updated statement today, and figured it would be good to get some generic code up here to reference in the future. Here is how to do a simple update that updates the values of one table, to another on a common key.
update
a
set
a.Field1 = b.Field1,
a.Field2 = b.Field2
from tableA a
inner join tableB b on a.fKey = b.pKey
where a.pKey = @someValue
@alexdwhite
alexdwhite / GetCardType.sql
Last active February 25, 2019 19:40
Function to determine credit card type from card number (SQL)
-- create the function in SQL
CREATE FUNCTION [dbo].[GetCardType] (@CardNum varchar(100))
RETURNS varchar(10)
AS
BEGIN
DECLARE @type varchar(10)
if (left(@CardNum, 1) = '4')
begin