Lead, LAG & CTE Victor Ivantsov.

Slides:



Advertisements
Similar presentations
Northwestern University Business Intelligence Solutions Cognos 8 Best Practices Volume 3 Advanced Developer Techniques.
Advertisements

Application Generator Merrill Networking Services.
Big Data Working with Terabytes in SQL Server Andrew Novick
Module 6: Working with Subqueries. Overview Introduction to Subqueries Using a Subquery as a Derived Table Using a Subquery as an Expression Using a Subquery.
Clarity Educational Community Clarity Educational Community Creating and Tuning SQL Queries that Engage Users.
Mary K. Olson PS Reporting Instance – Query Tool 101.
Concepts of Database Management Sixth Edition
Microsoft Office System UK Developers Conference Radisson Edwardian, Heathrow 29 th & 30 th June 2005.
Gain Performance & Scalability With RightNow Analytics
Version 1.0. MCAD MCSD MCPD Enterprise SQL MCTS MCT Software/Web Development Consultant Cryptography/Digital Signature Consultant SQL Server 2005/2008R2/2012.
Self Guided Tour for Query V8.4 Basic Features. 2 This Self Guided Tour is meant as a review only for Query V8.4 Basic Features and not as a substitute.
Concepts of Database Management Seventh Edition
© 2015 Jenzabar, Inc. James Mueller Graceland University Saturday May 30 th, 11:00am – 12:00pm 447: Cognos Customization Showcase ( and CX/JX II Track.
INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
102 VISTA VIEWS REPORT BUILDING PowerCampus Version
By: Matt Batalon, MCITP  Another form of temporary storage that can be queried or joined against, much like a table variable, temp.
Concepts of Database Management Seventh Edition
Reactive Database Access in Scala with Slick 3
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Robin Mullinix Systems Analyst GeorgiaFIRST Financials PeopleSoft Query: The Next Step.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Unit 4 Queries and Joins. Key Concepts Using the SELECT statement Statement clauses Subqueries Multiple table statements Using table pseudonyms Inner.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Indexes and Views Unit 7.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Writing Basic SQL SELECT Statements Lecture
There’s a particular style to it… Rob Hatton
 CONACT UC:  Magnific training   
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Sponsored by: Professional Association for SQL Server Advanced Reporting Services Slicers.
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
Authoring for Performance
Victoria Power BI User Group Meeting
Using Common Table Expressions
Practice writing SQL statements Discuss SQL UNION statement.
Tuning Transact-SQL Queries
Connect to SQL Server and run select statements
Data Virtualization Community Edition
Data Analysis with SQL Window Functions
Database Performance Tuning and Query Optimization
I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE
Power BI Performance …Tips and Techniques.
Using SQL to Prepare Data for Analysis
Discovering SSRS 2016 in Azure: Dataset to Deployment
Introduction to tabular models
Populating a Data Warehouse
Indexing Fundamentals
Chapter 4 Summary Query.
Indexing for Beginners
SQL Fundamentals in Three Hours
What’s new with SQL Server
Data Analysis with SQL Window Functions
1.4 Solving Absolute-Value Equations
Writing Basic SQL SELECT Statements
Make Your PACKAGES Communicate BETTER
Contents Preface I Introduction Lesson Objectives I-2
Chapter 11 Database Performance Tuning and Query Optimization
Building a Threat-Analytics Multi-Region Data Lake on AWS
1.4 Solving Absolute-Value Equations
All about Indexes Gail Shaw.
Row Level Security enhancements in 91SP3
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

Lead, LAG & CTE Victor Ivantsov

About VICTOR IVANTSOV Started with SQL Server 6.5 in 1996, still enjoy it Now on SQL 2016 Standard, SSIS, SSRS, T-SQL My Toastmaster club (Rivercity TM) meets every Tuesday @ 7:15 AM Enjoy running, soccer, music 904-351-6336 (voice, text) victor.ivantsov@gmail.com

Agenda Introduction: why I am addicted to cross/outer apply Deep dive #1: split string values into rows by delimiter Deep dive #2: support any user defined filter condition Adjournment, QnA

Big RecordsETS @dir @sort @total @limit @start

@sort As Column Expression

ORDER BY CLAUSE

SPLIT LEFT and RIGHT Values ‘Jacksonville, FL 33296’ ‘Smith Jr, Michael Peter’ ‘coverageAmount ( 7,500’ ‘UploadFile_usrid_12345.xls’ ‘3)’

Ugly & Buggy code

Reuse existing code Take existing function that split string values via XML Add item # to the list Escape special xml characters (&, <, > “) Use new LEAD sql keword

Split values via xml - Preparation

SPLIT VALUES – XML Ready

Split Values – Function Ready

LEAD – usage example https://docs.microsoft.com/en-us/sql/t-sql/functions/lead-transact-sql?view=sql-server-2017

Another complex function

Supported EXPRESSions Is_match = New computed column

LEFT OUTER JOIN SAME COMPLEX FUNCTION? SOLUTION #1 LEFT OUTER JOIN SAME COMPLEX FUNCTION? TOO MUCH COMPLEXITY FOR QUERY OPTIMIZER

MULTI STATEMENT FUNCTION SOLUTION #2 MULTI STATEMENT FUNCTION STILL TOO SLOW

LaG & CTE *

Q & A Victor Ivantsov 904-351-6336 (voice, text) victor.ivantsov@gmail.com Rivercity Toastmasters, club #892 meets every Tuesday @ 7:15 AM IHOP 3250 Hodges Blvd, Jacksonville, FL 32224