34
Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Embed Size (px)

Citation preview

Page 1: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Getting started with SQL Queries and Programming

Jeremy BrinkmanAssistant VP for Information TechnologyUniversity of Northwestern Ohio

Page 2: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• Private, Non-profit Institution• Founded in 1920• 4600+ students from all 50 states and 24

foreign countries• Five Colleges: College of Applied Technologies,

College of Business, College of Occupational Professions, College of Health Professions, Graduate College

University of Northwestern Ohio

www.unoh.edu

Page 3: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• The SQL developer’s toolbox• Locating data in Colleague• SQL query fundamentals

Presentation Overview

Page 4: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

The SQL Developer’s Toolbox

Page 5: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• SQL Server Management Studio

The SQL Developer’s Toolbox

Page 6: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• Colleague Screens– RDEL – RDEP– RFEI– RDSF

The SQL Developer’s Toolbox

Page 7: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• Colleague Screens Continued– EOFM

The SQL Developer’s Toolbox

Page 8: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• Simple but effective: browse the data

SELECT TOP 10 * FROM TABLE

The SQL Developer’s Toolbox

Page 9: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

• Other useful tools

– SQL Server Profiler

– Colleague Studio

– Red-gate SQL Prompt

The SQL Developer’s Toolbox

Page 10: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data in Colleague

Page 11: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

• Field help• Form/process help• F1

Page 12: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Page 13: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Lookup the field on RDEL to get the file name.

Page 14: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Match the file name from RDEL to the SQL table

Page 15: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Interpreting RDEL

• Replace the “.” with “_” to derive the SQL table name from the UniData file name.

• Data Fields (D) – data can be found inside the table listed in the File Name field.

• List Fields (L) – Data can be found in the _LS table version of the table in the File Name field. PERSON_LS is one example.

• Associated Fields (A) – Data can be found in a SQL table named for the association listed on RDEL.

• X Pointer and Q Pointer Fields – Related data can be found in the Secondary Pointer/File. For X Pointer fields, the pointer exists in the SQL table itself. For Q Pointer fields, the pointer exists in the _LS table.

Page 16: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Q Pointer example:

Page 17: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Q Pointer example in SQL Server:

Page 18: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Associated field example:

Page 19: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Associated field example in SQL Server:

Page 20: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Q Pointer + Association example:

Page 21: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

Q Pointer + Association in SQL:

Page 22: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Locating Data on Colleague Screens

A few more tips:• The POS field is used to store the position of

data in multivalued fields or associations.

• “VAR” fields found on Colleague forms do not represent actual fields in the SQL database.

• File Suites are often difficult to interpret. In general, when you see “ACYR” in a file, you can replace it with the file suite year.

Page 23: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SQL Query Fundamentals

Page 24: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SELECT < list of fields to return >FROM < tables >WHERE < data filters >ORDER BY < fields to sort >

Elements of a basic SQL Query

Page 25: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SELECT PERSON.FIRST_NAME, PERSON.LAST_NAMEFROM PERSONWHERE PERSON.LAST_NAME = ‘Flintstone’ORDER BY PERSON.FIRST_NAME

SQL Query Example #1

Page 26: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Coding Tip:

Always prefix your field names with a

table name or alias.

Coding Tip

Page 27: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Using a Computed Column

SQL Query Example #2

SELECT PERSON.FIRST_NAME, PERSON.LAST_NAME,

dbo.AGE(PERSON.ID)FROM PERSONWHERE PERSON.LAST_NAME = 'Flintstone'ORDER BY PERSON.FIRST_NAME

Page 28: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SELECT < list of fields to return >FROM < table 1 > INNER JOIN < table 2 > ON <table 1 field>=<table 2 field>WHERE < data filters >ORDER BY < fields to sort >

Let’s Join Another Table

Page 29: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SELECT PERSON.FIRST_NAME, PERSON.LAST_NAME, PERSON_LS.POS, PERSON_LS.PER_ETHNICSFROM PERSON INNER JOIN PERSON_LS ON PERSON_LS.ID = PERSON.IDWHERE PERSON.LAST_NAME = ‘Flintstone’ORDER BY PERSON.FIRST_NAME

SQL Query Example #3

Page 30: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Coding Tip:

Keep code clean by using proper indentation.

Coding Tip

Page 31: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Most Common Join Types

• INNER JOIN – Include only records where the join field(s) matches in the left and right table.

• LEFT OUTER JOIN – Include all records from the left table and only those in the right table that match the join field(s)

Page 32: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

SQL Query Example #4List all addresses for a person

SELECT PERSON.FIRST_NAME, PERSON.LAST_NAME, ADDRESS_LS.ADDRESS_LINES, ADDRESS.CITY, ADDRESS.STATE, ADDRESS.ZIPFROM PERSON INNER JOIN PSEASON ON PERSON.ID = PSEASON.ID INNER JOIN ADDRESS ON PSEASON.PERSON_ADDRESSES = ADDRESS.ADDRESS_ID INNER JOIN ADDRESS_LS ON ADDRESS.ADDRESS_ID = ADDRESS_LS.ADDRESS_ID AND ADDRESS_LS.POS = 1WHERE PERSON.LAST_NAME = 'Flintstone'

Page 33: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Questions?

Page 34: Getting started with SQL Queries and Programming Jeremy Brinkman Assistant VP for Information Technology University of Northwestern Ohio

Contact Information

Jeremy BrinkmanAssistant VP for Information TechnologyUniversity of Northwestern [email protected]