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

Post on 12-Jan-2016

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Getting started with SQL Queries and Programming

Jeremy BrinkmanAssistant VP for Information TechnologyUniversity 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

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

Presentation Overview

The SQL Developer’s Toolbox

• SQL Server Management Studio

The SQL Developer’s Toolbox

• Colleague Screens– RDEL – RDEP– RFEI– RDSF

The SQL Developer’s Toolbox

• Colleague Screens Continued– EOFM

The SQL Developer’s Toolbox

• Simple but effective: browse the data

SELECT TOP 10 * FROM TABLE

The SQL Developer’s Toolbox

• Other useful tools

– SQL Server Profiler

– Colleague Studio

– Red-gate SQL Prompt

The SQL Developer’s Toolbox

Locating Data in Colleague

Locating Data on Colleague Screens

• Field help• Form/process help• F1

Locating Data on Colleague Screens

Locating Data on Colleague Screens

Lookup the field on RDEL to get the file name.

Locating Data on Colleague Screens

Match the file name from RDEL to the SQL table

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.

Locating Data on Colleague Screens

Q Pointer example:

Locating Data on Colleague Screens

Q Pointer example in SQL Server:

Locating Data on Colleague Screens

Associated field example:

Locating Data on Colleague Screens

Associated field example in SQL Server:

Locating Data on Colleague Screens

Q Pointer + Association example:

Locating Data on Colleague Screens

Q Pointer + Association in SQL:

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.

SQL Query Fundamentals

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

Elements of a basic SQL Query

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

SQL Query Example #1

Coding Tip:

Always prefix your field names with a

table name or alias.

Coding Tip

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

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

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

Coding Tip:

Keep code clean by using proper indentation.

Coding Tip

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)

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'

Questions?

Contact Information

Jeremy BrinkmanAssistant VP for Information TechnologyUniversity of Northwestern Ohiojbrinkman@unoh.edu

top related