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 * | |
FROM [ORDER] ord | |
WHERE ord.OrderDate BETWEEN '20130101' AND '20130228'; | |
GO | |
/** Output **/ | |
Id OrderDate OrderNumber CustomerId TotalAmount | |
----------- ----------------------- ----------- ----------- --------------------------------------- | |
153 2013-01-01 00:00:00.000 542530 19 3063.00 | |
154 2013-01-01 00:00:00.000 542531 65 3868.60 |
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 "table_alias"."column_name1" AS "column_alias" | |
FROM "table_name" AS "table_alias"; |
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 cus.FirstName, | |
cus.LastName | |
FROM Customer cus; | |
GO | |
/** Output **/ | |
FirstName LastName | |
---------------------------------------- ---------------------------------------- | |
Paolo Accorti | |
Pedro Afonso |
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 "column_name" | |
FROM "table_name" | |
[WHERE "condition"] | |
ORDER BY "column_name" [ASC, DESC]; |
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 (cus.FirstName + ' ' + cus.LastName) AS "Full Name", | |
cus.City, | |
cus.Country, | |
cus.Phone | |
FROM Customer cus | |
ORDER BY cus.Id; | |
GO | |
Full Name City Country Phone | |
--------------------------------------------------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- |
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 UPPER(cus.FirstName) | |
FROM Customer cus; | |
GO | |
/** Output **/ | |
---------------------------------------- | |
PAOLO | |
PEDRO | |
MARIA | |
MIGUEL |
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 RIGHT(cus.FirstName, 2) | |
FROM Customer cus; | |
GO | |
/** Output**/ | |
---- | |
lo | |
ro | |
ia | |
el |
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 GETDATE(); | |
GO | |
/** Output **/ | |
----------------------- | |
2017-03-20 16:57:22.273 | |
SELECT DATEPART(yy, ord.OrderDate) | |
FROM [ORDER] ord; | |
GO |
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 DATENAME(weekday, GETDATE()); | |
GO | |
/** Output **/ | |
------------------------------ | |
Sunday | |
SELECT DATEDIFF(dd, '20170426', '20170725'); | |
GO | |
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 ISNULL(CONVERT(VARCHAR(MAX), ord.OrderDate), 'Sin Fecha') | |
FROM [ORDER] ord; | |
GO | |
/** Output **/ | |
-------------------- | |
Jul 4 2012 12:00AM | |
Jul 5 2012 12:00AM | |
Jul 8 2012 12:00AM | |
Jul 8 2012 12:00AM |