35
Query Developer User Query Developer User Group Group March 15, 2006 March 15, 2006

Query Developer User Group March 15, 2006. Tips and Techniques Cutting and pasting SQL between QM, Excel, and Access Filtering the list of tables in Excel

Embed Size (px)

Citation preview

Query Developer User GroupQuery Developer User Group

March 15, 2006March 15, 2006

Tips and TechniquesTips and Techniques

Cutting and pasting SQL between QM, Excel, Cutting and pasting SQL between QM, Excel, and Accessand AccessFiltering the list of tables in ExcelFiltering the list of tables in ExcelSaving a query in ExcelSaving a query in ExcelSQL Pass-through in AccessSQL Pass-through in AccessUsing parametersUsing parameters– ExcelExcel– AccessAccess

Changing the join typeChanging the join typeExamples of Advanced SQLExamples of Advanced SQL

Cutting and Pasting SQLCutting and Pasting SQL

Going from QM to ExcelGoing from QM to Excel– The query has to be in SQL, Prompted will not work The query has to be in SQL, Prompted will not work – Open the query in Edit or Display modeOpen the query in Edit or Display mode

Can also use option 5 from the University Provided Reports Can also use option 5 from the University Provided Reports menumenu

– Select and copy the SQL using standard techniquesSelect and copy the SQL using standard techniques– Open a new query in Excel or MS QueryOpen a new query in Excel or MS Query– Open the SQL window and paste the SQLOpen the SQL window and paste the SQL– Any parameters will have to be adjusted to meet MS Any parameters will have to be adjusted to meet MS

Query requirements (covered in the next section)Query requirements (covered in the next section)

Cutting and Pasting SQLCutting and Pasting SQL

Going from QM to AccessGoing from QM to Access– The query has to be in SQL, Prompted will not work The query has to be in SQL, Prompted will not work – Open the query in Edit or Display modeOpen the query in Edit or Display mode

Can also use option 5 from the University Provided Reports Can also use option 5 from the University Provided Reports menumenu

– Select and copy the SQL using standard techniquesSelect and copy the SQL using standard techniques– Open a new query in Access using Design ViewOpen a new query in Access using Design View– Open the SQL window and paste the SQLOpen the SQL window and paste the SQL– Table names have to be adjusted for Access (change Table names have to be adjusted for Access (change

DATACOLL.view to DATACOLL_view)DATACOLL.view to DATACOLL_view)– Any parameters will have to be adjusted to meet Any parameters will have to be adjusted to meet

Access requirements (covered in the next section)Access requirements (covered in the next section)

Cutting and Pasting SQLCutting and Pasting SQL

Going from Excel to AccessGoing from Excel to Access– Open the SQL window in MS QueryOpen the SQL window in MS Query– Copy to the clipboardCopy to the clipboard– Open the Access query SQL windowOpen the Access query SQL window– Paste from the clipboardPaste from the clipboard– Table names have to be adjusted for Access Table names have to be adjusted for Access

(change DATACOLL.view to (change DATACOLL.view to DATACOLL_view)DATACOLL_view)

– Enter the parameter prompt stringEnter the parameter prompt string

Filtering the list of tables in ExcelFiltering the list of tables in Excel

In the Add Tables dialog window, the list In the Add Tables dialog window, the list can be filtered by doing the followingcan be filtered by doing the following

Select DATACOLL from the Schema pull Select DATACOLL from the Schema pull downdown

Click Options button and make sure that Click Options button and make sure that only Views is selectedonly Views is selected

Saving a Query in ExcelSaving a Query in Excel

Saved with the sheet in the workbookSaved with the sheet in the workbook

Saved externallySaved externally– Default locationDefault location

C:\Document and Settings\userid\Application Data\C:\Document and Settings\userid\Application Data\Microsoft\QueriesMicrosoft\Queries

The Application Data folder is hiddenThe Application Data folder is hidden

– A location to share with othersA location to share with othersThis can be any you want; just like any other Save This can be any you want; just like any other Save As dialogAs dialog

Using a Saved Query in ExcelUsing a Saved Query in Excel

In the Choose Data Source window, there is an In the Choose Data Source window, there is an “Options” button that lets you choose the “Options” button that lets you choose the location of your data sourceslocation of your data sourcesBy default, it includes your ODBC data sources By default, it includes your ODBC data sources and queries stored in the default directory.and queries stored in the default directory.Click this button to add a directory. This Click this button to add a directory. This directory will be used to populate the Queries directory will be used to populate the Queries tab. This directory could be on a shared drive or tab. This directory could be on a shared drive or on your local hard drive.on your local hard drive.The Queries tab facilitates reuse of queriesThe Queries tab facilitates reuse of queries

SQL Pass-through in AccessSQL Pass-through in Access

Pass-through is turned on by clicking Pass-through is turned on by clicking Query -> SQL Specific -> Pass-throughQuery -> SQL Specific -> Pass-through

You need to turn this on when you have You need to turn this on when you have more advanced SQL than what Access more advanced SQL than what Access can handle.can handle.

You can’t use parameters You can’t use parameters

You have to use standard SQL naming You have to use standard SQL naming (DATACOLL.tablename)(DATACOLL.tablename)

Using Parameters in Excel, AccessUsing Parameters in Excel, Access

In the criteria window, enter the prompt In the criteria window, enter the prompt string enclosed in square brackets [ ]string enclosed in square brackets [ ]

In Access, if using more than 1 parameter, In Access, if using more than 1 parameter, use the Query Parameter dialog to set the use the Query Parameter dialog to set the order of the prompts (Query -> order of the prompts (Query -> Parameters)Parameters)

In Access, you can’t use parameters in a In Access, you can’t use parameters in a pass-through querypass-through query

Changing the Join TypeChanging the Join Type

ExcelExcel

AccessAccess

Click the join line between the 2 matching Click the join line between the 2 matching columns and select either a left outer join columns and select either a left outer join or a right outer joinor a right outer join

Notice that the line between the 2 columns Notice that the line between the 2 columns changeschanges

Advanced SQL ExamplesAdvanced SQL Examples

Fetch first n rows onlyFetch first n rows only

Left Outer JoinLeft Outer Join

Left Exception JoinLeft Exception Join

Full Outer JoinFull Outer Join

Case Expression Case Expression

Excluding zeroes from an average Excluding zeroes from an average calculationcalculation

FETCH FIRST n ROWS ONLYFETCH FIRST n ROWS ONLY

Sets the maximum number of rows to be Sets the maximum number of rows to be returnedreturned

Follows the ORDER BY clause if it is Follows the ORDER BY clause if it is presentpresent

If the ORDER BY clause is present, then If the ORDER BY clause is present, then the FETCH FIRST operation is performed the FETCH FIRST operation is performed on the sorted dataon the sorted data

FETCH FIRST n ROWS ONLYFETCH FIRST n ROWS ONLY

SELECT MAJ1_CURR, COUNT(*)SELECT MAJ1_CURR, COUNT(*)

FROM DATACOLL.STUDENTSFROM DATACOLL.STUDENTS

WHERE CURR_STDT = 'Y'WHERE CURR_STDT = 'Y'

GROUP BY MAJ1_CURRGROUP BY MAJ1_CURR

ORDER BY 2 DESC,1ORDER BY 2 DESC,1

FETCH FIRST 10 ROWS ONLYFETCH FIRST 10 ROWS ONLY

Left Outer JoinLeft Outer Join

A Left Outer Join returns values for all of the A Left Outer Join returns values for all of the rows from the first table (the table on the left) rows from the first table (the table on the left) and the values from the second table for the and the values from the second table for the rows that match. Any rows that do not have a rows that match. Any rows that do not have a match in the second table will return the null match in the second table will return the null value for all columns from the second table.value for all columns from the second table.

FROM T1 LEFT OUTER JOIN T2FROM T1 LEFT OUTER JOIN T2

ON T1.COLA = T2.COL1ON T1.COLA = T2.COL1

Left Outer JoinLeft Outer Join

This can be selected using the techniques This can be selected using the techniques on slide 8on slide 8

When would you use this?When would you use this?

Left Outer Join ExampleLeft Outer Join Example

select schl_code, schl_name, sum(stdt) as count select schl_code, schl_name, sum(stdt) as count from from (select schl_code, schl_name, case (select schl_code, schl_name, case when soc_sec is not null then 1 when soc_sec is not null then 1 else 0 end as stdt else 0 end as stdt from from datacoll.institutndatacoll.institutn i left outer join i left outer join (select soc_sec, hs_code from datacoll.fa05students (select soc_sec, hs_code from datacoll.fa05students where curr_stdt = 'Y' where curr_stdt = 'Y' and stu_class in ('FR','SO','JR','SR') and stu_class in ('FR','SO','JR','SR') and stu_type = 'FT') sand stu_type = 'FT') s on schl_code = hs_code) as high_school on schl_code = hs_code) as high_school group by schl_code, schl_name group by schl_code, schl_name order by count descorder by count desc

Left Exception JoinLeft Exception Join

A Left Exception Join returns only the rows A Left Exception Join returns only the rows from the left table that do not have a from the left table that do not have a match in the right table. Columns in the match in the right table. Columns in the result table that come from the right table result table that come from the right table have the null value.have the null value.

FROM T1 LEFT EXCEPTION JOIN T2FROM T1 LEFT EXCEPTION JOIN T2

ON T1.COLA = T2.COL1ON T1.COLA = T2.COL1

Left Exception JoinLeft Exception Join

The previous syntax will not work in AccessThe previous syntax will not work in Access

Has to be manually entered in the SQL window Has to be manually entered in the SQL window in Excel and Accessin Excel and Access– Access also will require pass-through to be setAccess also will require pass-through to be set

There is a work around for Excel and Access if There is a work around for Excel and Access if you don’t want to use the SQL windowyou don’t want to use the SQL window– Make the join a left outer joinMake the join a left outer join– Add the matching column from the right table to the Add the matching column from the right table to the

criteria and check for “Is Null”criteria and check for “Is Null”

Left Exception JoinLeft Exception Join

When would you use this?When would you use this?

Left Exception JoinLeft Exception Join

SELECT NAME, STU_CLASS, HS_CODESELECT NAME, STU_CLASS, HS_CODE

FROM DATACOLL.STUDENTS LEFT FROM DATACOLL.STUDENTS LEFT EXCEPTION JOIN EXCEPTION JOIN DATACOLL.INSTITUTNDATACOLL.INSTITUTN

ON HS_CODE = SCHL_CODEON HS_CODE = SCHL_CODE

WHERE CURR_STDT = 'Y'WHERE CURR_STDT = 'Y'

AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')

AND HS_CODE <> ' 'AND HS_CODE <> ' '

Full Outer JoinFull Outer Join

The Full Outer JoinThe Full Outer Join includes the inner join includes the inner join (the rows that match) and the rows from (the rows that match) and the rows from both the left and right tables that do not both the left and right tables that do not match.match.The Full Outer Join is not included in this The Full Outer Join is not included in this version of SQL, but it can be simulated.version of SQL, but it can be simulated.You simulate a Full Outer Join by using a You simulate a Full Outer Join by using a Left Outer Join union’ed with a Right Left Outer Join union’ed with a Right Exception JoinException Join

Full Outer Join ExampleFull Outer Join Example

SELECT S.SOC_SEC, SUBSTR(GRE_TEST_CCYYMM,1,4)||'/'||SELECT S.SOC_SEC, SUBSTR(GRE_TEST_CCYYMM,1,4)||'/'|| SUBSTR(GRE_TEST_CCYYMM,5,2), G.SOC_SECSUBSTR(GRE_TEST_CCYYMM,5,2), G.SOC_SECFROM DATACOLL.STDT S LEFT OUTER JOIN DATACOLL.GRETST FROM DATACOLL.STDT S LEFT OUTER JOIN DATACOLL.GRETST

GGON S.SOC_SEC = G.SOC_SECON S.SOC_SEC = G.SOC_SECWHERE STU_CLASS = 'GM'WHERE STU_CLASS = 'GM'UNIONUNIONSELECT S.SOC_SEC, SUBSTR(GRE_TEST_CCYYMM,1,4)||'/'||SELECT S.SOC_SEC, SUBSTR(GRE_TEST_CCYYMM,1,4)||'/'|| SUBSTR(GRE_TEST_CCYYMM,5,2), G.SOC_SECSUBSTR(GRE_TEST_CCYYMM,5,2), G.SOC_SECFROM DATACOLL.STDT S RIGHT EXCEPTION JOIN FROM DATACOLL.STDT S RIGHT EXCEPTION JOIN

DATACOLL.GRETST GDATACOLL.GRETST GON S.SOC_SEC = G.SOC_SECON S.SOC_SEC = G.SOC_SEC

Case ExpressionsCase Expressions

The CASE expression can be used to The CASE expression can be used to easily manipulate the data in a columneasily manipulate the data in a column– It can be used to change codes into It can be used to change codes into

meaningful wordsmeaningful words– It can be used to provide special sort orderIt can be used to provide special sort order

In Excel, has to be in SQL windowIn Excel, has to be in SQL window

In Access, has to be in SQL window with In Access, has to be in SQL window with pass-through turned on. pass-through turned on.

Case ExpressionsCase ExpressionsSELECT A.NAME_REVERSED,SELECT A.NAME_REVERSED, CASE SUBSTR(C.HALL,1,4) WHEN 'BLSH' THEN '%BLAIR-SHANNON HOUSE%'CASE SUBSTR(C.HALL,1,4) WHEN 'BLSH' THEN '%BLAIR-SHANNON HOUSE%' WHEN 'FRED' THEN '%FREUDENBERGER HOUSE%'WHEN 'FRED' THEN '%FREUDENBERGER HOUSE%' WHEN 'WOOD' THEN '%WOODS HOUSE%'WHEN 'WOOD' THEN '%WOODS HOUSE%' WHEN 'HAMH' THEN '%HAMMONS HOUSE%'WHEN 'HAMH' THEN '%HAMMONS HOUSE%' WHEN 'NEWH' THEN '%NEW HALL%'WHEN 'NEWH' THEN '%NEW HALL%' WHEN 'SCHO' THEN '%SCHOLARS HOUSE%'WHEN 'SCHO' THEN '%SCHOLARS HOUSE%' WHEN 'EAPT' THEN '%ELM APARTMENTS%'WHEN 'EAPT' THEN '%ELM APARTMENTS%' WHEN 'SUNV' THEN 'SUNVILLA TOWER%'WHEN 'SUNV' THEN 'SUNVILLA TOWER%' WHEN 'KENT' THEN '%KENTWOOD HALL%'WHEN 'KENT' THEN '%KENTWOOD HALL%' WHEN 'DAPT' THEN '%DOGWOOD APARTMENTS%'WHEN 'DAPT' THEN '%DOGWOOD APARTMENTS%' WHEN 'SAPT' THEN '%SUNVILLA APARTMENTS%'WHEN 'SAPT' THEN '%SUNVILLA APARTMENTS%' WHEN 'KAPT' THEN '%KENTWOOD SOUTH APTS%'WHEN 'KAPT' THEN '%KENTWOOD SOUTH APTS%' WHEN 'WELL' THEN '%WELLS HOUSE%'WHEN 'WELL' THEN '%WELLS HOUSE%' END AS HALL,END AS HALL,A.PERMNT_STREET, A.PERMNT_CITY, A.PERMNT_STATE, A.PERMNT_ZIPA.PERMNT_STREET, A.PERMNT_CITY, A.PERMNT_STATE, A.PERMNT_ZIP

Case ExpressionsCase Expressions

SELECT NAME, STU_CLASS, CASE(STU_CLASS)SELECT NAME, STU_CLASS, CASE(STU_CLASS) WHEN('FR') THEN 1WHEN('FR') THEN 1 WHEN('SO') THEN 2WHEN('SO') THEN 2 WHEN('JR') THEN 3WHEN('JR') THEN 3 WHEN('SR') THEN 4WHEN('SR') THEN 4 ELSE 999ELSE 999 END AS CLASSEND AS CLASSFROM DATACOLL.STUDENTSFROM DATACOLL.STUDENTSWHERE SEM_PNTR = ‘SP' AND YEAR_PNTR = '2006'WHERE SEM_PNTR = ‘SP' AND YEAR_PNTR = '2006'AND CURR_STDT = 'Y'AND CURR_STDT = 'Y'AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')ORDER BY CLASS, NAMEORDER BY CLASS, NAME

Case ExpressionsCase Expressions

SELECT DISTINCTSELECT DISTINCTA.SOC_SEC, A.NAME, A.MAJ1_CURR, A.MAJ2_CURR, A.SOC_SEC, A.NAME, A.MAJ1_CURR, A.MAJ2_CURR,

A.STU_CLASS, B.COURSE_CODE,A.STU_CLASS, B.COURSE_CODE,B.COURSE_NO, B.SECTION, B.SEMESTER,B.COURSE_NO, B.SECTION, B.SEMESTER,CASE(B.SEMESTER)CASE(B.SEMESTER) WHEN('FA') THEN 'Fall'WHEN('FA') THEN 'Fall' WHEN('SP') THEN 'Spring'WHEN('SP') THEN 'Spring' WHEN('SU') THEN 'Summer'WHEN('SU') THEN 'Summer' ELSE ' 'ELSE ' ' ENDENDFROM DATACOLL.STDT A,DATACOLL.CLASSES BFROM DATACOLL.STDT A,DATACOLL.CLASSES B

Where can a CASE expression be Where can a CASE expression be used?used?

Anywhere an expression is allowed in a Anywhere an expression is allowed in a SQL statementSQL statementSELECT clauseSELECT clauseWHERE clauseWHERE clauseHAVING clauseHAVING clauseBuilt-in FunctionBuilt-in FunctionIN (list)IN (list)ORDER BY clauseORDER BY clause

Can I use a subselect inside a Can I use a subselect inside a CASE expression?CASE expression?

SELECT NAME, STU_CLASS, COMB_UG_GPA, CASESELECT NAME, STU_CLASS, COMB_UG_GPA, CASE WHEN (SELECT SUM(CREDIT_HOURS) FROM WHEN (SELECT SUM(CREDIT_HOURS) FROM

DATACOLL.CLASSES CDATACOLL.CLASSES C WHERE A.SOC_SEC = C.SOC_SEC AND YEAR = '2006'WHERE A.SOC_SEC = C.SOC_SEC AND YEAR = '2006' AND SEMESTER = ‘SP') >= 12 THEN 'FULL-TIME'AND SEMESTER = ‘SP') >= 12 THEN 'FULL-TIME' WHEN (SELECT SUM(CREDIT_HOURS) FROM WHEN (SELECT SUM(CREDIT_HOURS) FROM

DATACOLL.CLASSES CDATACOLL.CLASSES C WHERE A.SOC_SEC = C.SOC_SEC AND YEAR = '2006'WHERE A.SOC_SEC = C.SOC_SEC AND YEAR = '2006' AND SEMESTER = ‘SP') < 12 THEN 'PART-TIME'AND SEMESTER = ‘SP') < 12 THEN 'PART-TIME' ELSE 'DOES NOT COUNT' END AS STATUSELSE 'DOES NOT COUNT' END AS STATUSFROM DATACOLL.STUDENTS AFROM DATACOLL.STUDENTS AWHERE SEM_PNTR = ‘SP'WHERE SEM_PNTR = ‘SP'AND YEAR_PNTR = '2006’AND YEAR_PNTR = '2006’AND CURR_STDT = 'Y'AND CURR_STDT = 'Y'AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')

A More Efficient QueryA More Efficient Query

SELECT NAME, STU_CLASS, COMB_UG_GPA, CASESELECT NAME, STU_CLASS, COMB_UG_GPA, CASE WHEN CREDIT_HOURS >= 12 THEN 'FULL-TIME'WHEN CREDIT_HOURS >= 12 THEN 'FULL-TIME' WHEN CREDIT_HOURS < 12 THEN 'PART-TIME'WHEN CREDIT_HOURS < 12 THEN 'PART-TIME' ELSE 'DOES NOT COUNT' END AS STATUSELSE 'DOES NOT COUNT' END AS STATUSFROM DATACOLL.STUDENTS A,FROM DATACOLL.STUDENTS A,(SELECT SUM(CREDIT_HOURS) AS CREDIT_HOURS FROM (SELECT SUM(CREDIT_HOURS) AS CREDIT_HOURS FROM

DATACOLL.CLASSESDATACOLL.CLASSES WHERE SEMESTER = 'SP' AND YEAR = '2006') AS FULLPARTWHERE SEMESTER = 'SP' AND YEAR = '2006') AS FULLPARTWHERE SEM_PNTR = 'SP'WHERE SEM_PNTR = 'SP'AND YEAR_PNTR = '2006'AND YEAR_PNTR = '2006'AND CURR_STDT = 'Y'AND CURR_STDT = 'Y'AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')

Using CASE in an ORDER BYUsing CASE in an ORDER BY

SELECT NAME_REVERSED, PERMNT_STATESELECT NAME_REVERSED, PERMNT_STATEFROM DATACOLL.ADDRESSESFROM DATACOLL.ADDRESSESWHERE SOC_SEC BETWEEN '496000000' AND WHERE SOC_SEC BETWEEN '496000000' AND

'499999999''499999999'ORDER BYORDER BY CASE PERMNT_STATECASE PERMNT_STATE WHEN ‘IL' THEN 0WHEN ‘IL' THEN 0 WHEN ' ' THEN 999WHEN ' ' THEN 999 ELSE 1ELSE 1 END,END, PERMNT_STATEPERMNT_STATE

Using Case in an ORDER BYUsing Case in an ORDER BY

SELECT NAME, MAJ1_CURR, STU_CLASS, SELECT NAME, MAJ1_CURR, STU_CLASS, COMB_UG_GPACOMB_UG_GPA

FROM DATACOLL.STDTFROM DATACOLL.STDTWHERE MAJ1_DEPT = 'CI'WHERE MAJ1_DEPT = 'CI'AND CURR_STDT = 'Y'AND CURR_STDT = 'Y'AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')ORDER BY CASE STU_CLASSORDER BY CASE STU_CLASSWHEN 'FR' THEN 1WHEN 'FR' THEN 1WHEN 'SO' THEN 2WHEN 'SO' THEN 2WHEN 'JR' THEN 3WHEN 'JR' THEN 3WHEN 'SR' THEN 4WHEN 'SR' THEN 4END, COMB_UG_GPAEND, COMB_UG_GPA

Using an IN list in a CASE Using an IN list in a CASE expressionexpression

SELECT NAME, STU_CLASS, CASE(STU_CLASS)SELECT NAME, STU_CLASS, CASE(STU_CLASS) WHEN STU_CLASS IN ('FR‘, ‘SO’) THEN ‘LOWER WHEN STU_CLASS IN ('FR‘, ‘SO’) THEN ‘LOWER

DIVISION’DIVISION’WHEN STU_CLASS IN ('JR‘, ‘SR’) THEN ‘UPPER WHEN STU_CLASS IN ('JR‘, ‘SR’) THEN ‘UPPER

DIVISION’DIVISION’ELSE 999ELSE 999 END AS CLASSEND AS CLASSFROM DATACOLL.STUDENTSFROM DATACOLL.STUDENTSWHERE CURR_STDT = 'Y'WHERE CURR_STDT = 'Y'AND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')ORDER BY CLASS, NAMEORDER BY CLASS, NAME

Eliminating zeroes from a Eliminating zeroes from a calculationcalculation

SELECT NAME, SOC_SEC, HNRS_ACT, SELECT NAME, SOC_SEC, HNRS_ACT, STU_CLASS, SMS_UG_CUM_GPA, STU_CLASS, SMS_UG_CUM_GPA, ACT_COMP_STD,ACT_COMP_STD,

FIN_AID, SEXFIN_AID, SEXFROM DATACOLL.STUDENTSFROM DATACOLL.STUDENTSWHERE HNRS_ACT = 'C' AND REG_SPR = WHERE HNRS_ACT = 'C' AND REG_SPR =

&YEAR&YEARAND (STU_CLASS ='FR' OR STU_CLASS ='SO' AND (STU_CLASS ='FR' OR STU_CLASS ='SO'

OR STU_CLASS ='JR' OR STU_CLASS = 'SR')OR STU_CLASS ='JR' OR STU_CLASS = 'SR')AND NOT NAME = 'AAA FAKE D'AND NOT NAME = 'AAA FAKE D'ORDER BY 5, 1ORDER BY 5, 1

Eliminating zeroes from a Eliminating zeroes from a calculationcalculation

SELECT NAME, SOC_SEC, HNRS_ACT, SELECT NAME, SOC_SEC, HNRS_ACT, STU_CLASS, NULLIF(SMS_UG_CUM_GPA,0),STU_CLASS, NULLIF(SMS_UG_CUM_GPA,0),

NULLIF(ACT_COMP_STD,0),NULLIF(ACT_COMP_STD,0),FIN_AID, SEXFIN_AID, SEXFROM DATACOLL.STUDENTSFROM DATACOLL.STUDENTSWHERE HNRS_ACT = 'C' AND REG_SPR = WHERE HNRS_ACT = 'C' AND REG_SPR =

&YEAR&YEARAND STU_CLASS IN ('FR','SO','JR','SR')AND STU_CLASS IN ('FR','SO','JR','SR')AND NOT NAME = 'AAA FAKE D'AND NOT NAME = 'AAA FAKE D'ORDER BY 5, 1ORDER BY 5, 1