IF EXISTS(SELECT *FROM Northwind.dbo.CustomersWHERE CustomerId = 'ALFKI')PRINT 'Need to update Customer Record ALFKI'ELSEPRINT 'Need to add Customer Record ALFKI'
IF EXISTS(SELECT *FROM Northwind.dbo.CustomersWHERE CustomerId = 'LARSE')PRINT 'Need to update Customer Record LARSE'ELSEPRINT 'Need to add Customer Record LARSE'
INSERT INTO customers (last_name, first_name, city)SELECT 'Doe', 'John', 'Chicago' FROM dualWHERE NOT EXISTS(SELECT '1' from customerswhere last_name = 'Doe'and first_name = 'John'and city = 'Chicago');
SELECT OrderID, Quantity,CASEWHEN Quantity > 30 THEN "The quantity is greater than 30"WHEN Quantity = 30 THEN "The quantity is 30"ELSE "The quantity is under 30"END AS QuantityTextFROM OrderDetails;
SELECT
(CASEWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1001' THEN 'DM'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1002' THEN 'GS'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1003' THEN 'MB'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1004' THEN 'MP'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1005' THEN 'PL'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1008' THEN 'DM-27'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1011' THEN 'PB'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1012' THEN 'UT-2'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1013' THEN 'JGC'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1014' THEN 'SB'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1015' THEN 'IR'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1016' THEN 'UT-3'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1017' THEN 'UT-4'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1019' THEN 'KR'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1020' THEN 'SYB-SB'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1021' THEN 'GR'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1022' THEN 'SYB-KP'WHEN RIGHT((LEFT(POSID,5)),4) LIKE '1026' THEN 'BNS'
ELSE ''END) AS OUTLET
FROM matrixcrm.Transact