Skip to content

Instantly share code, notes, and snippets.

View ArCiGo's full-sized avatar
🎯
Learning

Armando Cifuentes ArCiGo

🎯
Learning
View GitHub Profile
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
SELECT "table_alias"."column_name1" AS "column_alias"
FROM "table_name" AS "table_alias";
SELECT cus.FirstName,
cus.LastName
FROM Customer cus;
GO
/** Output **/
FirstName LastName
---------------------------------------- ----------------------------------------
Paolo Accorti
Pedro Afonso
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC];
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
--------------------------------------------------------------------------------- ---------------------------------------- ---------------------------------------- --------------------
SELECT UPPER(cus.FirstName)
FROM Customer cus;
GO
/** Output **/
----------------------------------------
PAOLO
PEDRO
MARIA
MIGUEL
SELECT RIGHT(cus.FirstName, 2)
FROM Customer cus;
GO
/** Output**/
----
lo
ro
ia
el
SELECT GETDATE();
GO
/** Output **/
-----------------------
2017-03-20 16:57:22.273
SELECT DATEPART(yy, ord.OrderDate)
FROM [ORDER] ord;
GO
SELECT DATENAME(weekday, GETDATE());
GO
/** Output **/
------------------------------
Sunday
SELECT DATEDIFF(dd, '20170426', '20170725');
GO
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