Skip to content

Instantly share code, notes, and snippets.


Alex White alexdwhite

View GitHub Profile
alexdwhite / GetCardType.sql
Last active February 25, 2019 19:40
Function to determine credit card type from card number (SQL)
View GetCardType.sql
-- create the function in SQL
CREATE FUNCTION [dbo].[GetCardType] (@CardNum varchar(100))
RETURNS varchar(10)
DECLARE @type varchar(10)
if (left(@CardNum, 1) = '4')
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.
View Sample SQL Update with Join statement
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 / SQLTempTableLoop
Last active December 29, 2015 09:29
SQL Temp Table Loop
View SQLTempTableLoop
-- 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