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
public sealed class Program | |
{ | |
private static void Main() | |
{ | |
Console.Write("Server End Point: "); | |
var userInput = Console.ReadLine(); | |
if (userInput != null) | |
{ | |
var endPoint = new IPEndPoint(IPAddress.Parse(userInput), 25565); | |
var resolver = new ServerInformationResolver(); |
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
const string ConnectionString = | |
"Data Source=DESKTOPPC;Initial Catalog=TSQL2012;Integrated Security=True"; | |
using (var connection = new SqlConnection(ConnectionString)) | |
{ | |
const string Query = "SELECT * FROM Sales.Orders WHERE custid = 71;"; | |
using (var adapter = new SqlDataAdapter(Query, connection)) | |
{ | |
var result = new DataTable(); |
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
USE TSQL2012; | |
IF OBJECT_ID('vendor') IS NOT NULL | |
DROP TABLE vendor | |
CREATE TABLE Vendor | |
( | |
VendorID INT IDENTITY PRIMARY KEY, | |
VendorName VARCHAR(32), | |
VendorEmail VARCHAR(200) |
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
USE TSQL2012; | |
SELECT productid, productname, categoryid, | |
CASE categoryid | |
WHEN 1 THEN 'Beverages' | |
WHEN 2 THEN 'Condiments' | |
WHEN 3 THEN 'Confections' | |
WHEN 4 THEN 'Dairy Products' | |
WHEN 5 THEN 'Grains/Cereals' | |
WHEN 6 THEN 'Meat/Poultry' |
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
USE TSQL2012; | |
SELECT custid, region, city | |
FROM Sales.Customers | |
WHERE ISNULL(region, '') <> 'WA' | |
WHERE region <> 'WA' | |
OR region IS NULL | |
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
-- Prints the sub-string located at the given start index for the given length | |
PRINT SUBSTRING('hello world', 6, 6); | |
-- Prints the sub-string located N characters to the RIGHT | |
PRINT RIGHT('hello world', 5); | |
-- Prints the sub-string located N characters to the LEFT | |
PRINT LEFT('hello world', 5); | |
-- Prints the amount of characters in the string |
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
SELECT empid, firstname + N' ' + lastname AS full_name | |
FROM HR.Employees | |
SELECT | |
empid, | |
--country + N', ' + region + N', ' + city AS location | |
--country + COALESCE(N',' + region, N'') + N',' + city AS location | |
CONCAT(country + N', ', region + N', ', + city ) AS location | |
FROM HR.Employees |
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
-- The % (Percent) Wildcard | |
SELECT empid, lastname | |
FROM HR.Employees | |
WHERE lastname LIKE N'D%'; | |
-- The _ (Underscores) Wildcard | |
SELECT empid, firstname, lastname | |
FROM HR.Employees | |
WHERE firstname LIKE N'___a'; |
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
-- Note that the proceeding queries interpert the date | |
-- differently based on the language (culture): | |
SET LANGUAGE BRITISH; | |
PRINT CAST('02/12/2007' AS DATETIME); | |
SET LANGUAGE us_english; | |
PRINT CAST('02/12/2007' AS DATETIME); |
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
-- In most cases, when you apply a manipulation on the filtered | |
-- column, SQL Server cannot use an index in an efficient manner: | |
SELECT orderid, custid, empid, orderdate | |
FROM Sales.Orders | |
WHERE YEAR(orderdate) = 2007 | |
-- To have the potentioal to use an index efficiently, you need | |
-- to revise the predicates so that there is no manipulation on | |
-- the filtered column: |