View GetCardType.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
View Sample SQL Update with Join statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View SQLTempTableLoop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |