This file contains hidden or 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
DECLARE @wealth d_wealth = 1000000.00 -- SQL 2008 only | |
IF @wealth > 10000 | |
BEGIN | |
PRINT 'Yes My lord!' | |
END | |
ELSE | |
BEGIN | |
PRINT 'Go to work you peasant!' | |
END |
This file contains hidden or 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
DECLARE @wealth d_wealth | |
SELECT @wealth = 1000000.00 | |
GO | |
DECLARE @wealth d_wealth = 1000000.00 -- SQL 2008 only |
This file contains hidden or 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 PROCEDURE p_get_family_info (@family d_last_name = null) | |
AS | |
SELECT p.first_name | |
, p.last_name | |
, p.alias | |
, r.name as region | |
, f.wealth | |
FROM t_person p | |
JOIN t_family f | |
ON p.last_name = f.name |
This file contains hidden or 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 VIEW v_person | |
AS | |
SELECT p.first_name, p.last_name, r.region | |
FROM t_person p | |
JOIN t_family f | |
ON p.last_name = f.name | |
JOIN t_region r | |
ON f.region_id = r.region_id | |
GO |
This file contains hidden or 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 table to store region info with primary key on id | |
if type_id('d_region_id') is null | |
create type d_region_id from int | |
if type_id('d_population') is null | |
create type d_population from int | |
if type_id('d_surface') is null | |
create type d_surface from numeric(14,2) | |
GO | |
if object_id('t_region') is null |
This file contains hidden or 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
SELECT CASE WHEN name = '' THEN 'There is no name' | |
WHEN name = 'Snow' THEN 'The bastard' | |
ELSE name | |
END | |
FROM t_family |
This file contains hidden or 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
SELECT CHARINDEX('X', | |
'There is a hidden X in this string') |
This file contains hidden or 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
select UPPER('I''m in all caps!!!') | |
select LOWER('I''M ALL IN LOWERCASE!!!') |
This file contains hidden or 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
select SUBSTRING('aaaxxxbbb', 4, 3) | |
select LEFT('aaaxxxbbb', 3) | |
select RIGHT('aaaxxxbbb', 3) |
This file contains hidden or 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
SELECT REPLACE(name, 'a', 'o') | |
FROM t_family |