10 | Programming with Transact-SQL Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Preface Demo A Quick Thank You How Did We Do It?
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Co- location Mass Market Managed Hosting ISV Hosting.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
Migrating to Windows Azure SQL Database Name Title Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
Windows Azure Connect Name Title Microsoft Corporation.
NEXT: Overview – Sharing skills & code.
Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Nick Scott | Dynamics CRM Consultant with BKD Technologies.
Building Social Games for Windows 8 with Windows Azure Name Title Microsoft Corporation.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
SQL Server SQL Azure Visual Studio“Quadrant” SQL Server Modeling Services Entity Framework ADO.NET“M”/EDM Data Services …
Ian Ellison-Taylor General Manager Microsoft Corporation PC27.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
03 | Word Templates Brian Meier| Senior Lead Program Manager.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
Advanced SQL Azure Database Name Title Microsoft Corporation.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
Windows Azure SQL Data Sync Name Title Microsoft Corporation.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
03 | Object-Oriented Programming Gerry O’Brien | Technical Content Development Manager Paul Pardi | Senior Content Publishing Manager.
04 | Business Analyzer Brian Meier| Senior Lead Program Manager.
Demo Fest of Some Leading Store Apps Module 2.

IoCompleteRequest (Irp);... p = NULL; …f(p);
10 | Programming with Transact-SQL
Возможности Excel 2010, о которых следует знать
C++ Programming L3 . Control Structures kkkkkkkkkkkkkk
Title of Presentation 11/22/2018 3:34 PM
Title of Presentation 12/2/2018 3:48 PM
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
Presentation transcript:

10 | Programming with Transact-SQL Graeme Malcolm | Senior Content Developer, Microsoft Geoff Allix | Principal Technologist, Content Master

Batches Comments Variables Conditional Branching Loops Stored Procedures Module Overview

Batches Batches are sets of commands sent to SQL Server as a unit Batches determine variable scope, name resolution To separate statements into batches, use a separator: –SQL Server tools use the GO keyword –GO is not a T-SQL command! –GO [count] executes the batch the specified number of times SELECT * FROM Production.Product; SELECT * FROM Sales.Customer; GO SELECT * FROM Production.Product; SELECT * FROM Sales.Customer; GO

Comments Marks T-SQL code as a comment: –For a block, enclose it between /* and */ characters –For inline text, precede the comments with -- T-SQL Editors typically color-code comments, as shown above /* This is a block of commented code */ /* This is a block of commented code */ --This line of text will be ignored

Variables Variables are objects that allow storage of a value for use later in the same batch Variables are defined with the DECLARE keyword –Variables can be declared and initialized in the same statement Variables are always local to the batch in which they're declared and go out of scope when the batch ends --Declare and initialize variables nvarchar(5)='L'; --Use variables in statements SELECT * FROM Production.Product WHERE and GO --Declare and initialize variables nvarchar(5)='L'; --Use variables in statements SELECT * FROM Production.Product WHERE and GO

DEMO Using Variables

Conditional Branching IF…ELSE uses a predicate to determine the flow of the code –The code in the IF block is executed if the predicate evaluates to TRUE –The code in the ELSE block is executed if the predicate evaluates to FALSE or UNKNOWN IS NULL SELECT * FROM Production.Product; ELSE SELECT * FROM Production.Product WHERE Color IS NULL SELECT * FROM Production.Product; ELSE SELECT * FROM Production.Product WHERE Color

DEMO Using IF…ELSE

Looping WHILE enables code to execute in a loop Statements in the WHILE block repeat as the predicate evaluates to TRUE The loop ends when the predicate evaluates to FALSE or UNKNOWN Execution can be altered by BREAK or CONTINUE AS INT = AS NVARCHAR(20); <=5 BEGIN = lastname FROM Sales.Customer WHERE customerid += 1; END; AS INT = AS NVARCHAR(20); <=5 BEGIN = lastname FROM Sales.Customer WHERE customerid += 1; END; CREATE PROCEDURE SalesLT.GetProductsByCategory INT = NULL) AS IS NULL SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product ELSE SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product WHERE ProductCategoryID CREATE PROCEDURE SalesLT.GetProductsByCategory INT = NULL) AS IS NULL SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product ELSE SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product WHERE ProductCategoryID

DEMO Demo: Using WHILE

Stored Procedures Database objects that encapsulate Transact-SQL code Can be parameterized –Input parameters –Output parameters Executed with the EXECUTE command CREATE PROCEDURE SalesLT.GetProductsByCategory INT = NULL) AS IS NULL SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product ELSE SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product WHERE ProductCategoryID CREATE PROCEDURE SalesLT.GetProductsByCategory INT = NULL) AS IS NULL SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product ELSE SELECT ProductID, Name, Color, Size, ListPrice FROM SalesLT.Product WHERE ProductCategoryID EXECUTE SalesLT.GetProductsByCategory 6;

DEMO Creating a Stored Procedure

Batches Comments Variables Conditional Branching Loops Stored Procedure Lab: Programming with Transact-SQL Programming with Transact-SQL

©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.