stored procedures (dynamic order by + web assistant wizard) kevin penny, mmcp [email protected]

14
Stored Procedures Stored Procedures (dynamic Order By + Web (dynamic Order By + Web Assistant Wizard) Assistant Wizard) Kevin Penny, MMCP Kevin Penny, MMCP [email protected] [email protected]

Upload: shawn-payne

Post on 30-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Stored ProceduresStored Procedures(dynamic Order By + Web (dynamic Order By + Web

Assistant Wizard)Assistant Wizard)

Kevin Penny, MMCPKevin Penny, MMCP

[email protected]@hotgigs.com

Page 2: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

AdvantagesAdvantages Pre-compilation = faster executionPre-compilation = faster execution Less Data transferred across networkLess Data transferred across network

EXAMPLE:EXAMPLE: exec sp_getproducts 12,234 exec sp_getproducts 12,234 vs.vs. SELECT Employees.Country, Employees.LastName, Employees.FirstName, SELECT Employees.Country, Employees.LastName, Employees.FirstName,

Orders.ShippedDate, Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal AS SaleAmountOrders.OrderID, "Order Subtotals".Subtotal AS SaleAmount

FROM Employees INNER JOIN FROM Employees INNER JOIN (Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order (Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order

Subtotals".OrderID) Subtotals".OrderID) ON Employees.EmployeeID = Orders.EmployeeIDON Employees.EmployeeID = Orders.EmployeeID

Re-usable execution plans used by the database Re-usable execution plans used by the database server for each procserver for each proc

More Secure (for inputted data)More Secure (for inputted data)

Page 3: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

DisadvantagesDisadvantages

More skill required to writeMore skill required to write May find it to be less flexible than May find it to be less flexible than

simple CFQUERY execution.simple CFQUERY execution. More planning needed for proper More planning needed for proper

implementation (not always a bad implementation (not always a bad thing!)thing!)

Page 4: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Dynamic Order by Dynamic Order by StatementStatement

You need to define all possible You need to define all possible columns that will be ordered by in columns that will be ordered by in your procedureyour procedure

Your Ordered by columns must be Your Ordered by columns must be grouped based on data type!grouped based on data type!

Your Order Direction must be Your Order Direction must be accounted for as well (i.e. ascending accounted for as well (i.e. ascending or descending)or descending)

Page 5: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Sample Order By Sample Order By

Demonstration Example: Northwind Demonstration Example: Northwind Database – Employee Sales By Database – Employee Sales By CountryCountry

Page 6: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com
Page 7: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

COLD FUSION ImplementationCOLD FUSION Implementation

Simple as passing the ‘parameters’ Simple as passing the ‘parameters’ through the url or through a formthrough the url or through a form

i.e. ?i.e. ?bdate=1/1/1900&edate=1/1/2005&Obdate=1/1/1900&edate=1/1/2005&Orderby=Company&SortDirection=ascrderby=Company&SortDirection=asc

Page 8: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

CFSTOREDPROCCFSTOREDPROC

The call to the Procedure:The call to the Procedure:

Page 9: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Using the SQL 2K Web AssistantUsing the SQL 2K Web Assistant

Using the Web Using the Web Assistant to create Assistant to create some great simple some great simple reports leveraging reports leveraging your Database your Database Server to Create Server to Create the reports, in a the reports, in a great paginated great paginated wayway

Page 10: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Why?Why?

Let the Database create some great Let the Database create some great ‘offline’ pages with pagination with ‘offline’ pages with pagination with NO Cold fusion coding neededNO Cold fusion coding needed

Take some load off the Application Take some load off the Application ServerServer

Give your customers / clients their Give your customers / clients their data by creating web assistants data by creating web assistants reports for stored procs you’ve reports for stored procs you’ve already createdalready created

Page 11: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Keys to SuccessKeys to Success Need a flexible way Need a flexible way

to change your to change your report without report without having to go having to go through the Setup through the Setup Wizard Each time Wizard Each time

Need a way to Need a way to manually re-manually re-generate them, or generate them, or schedule their schedule their execution (Job).execution (Job).

Use a stored Use a stored procedure that will procedure that will execute the report execute the report (if report changes (if report changes you can make the you can make the easy change w/in easy change w/in the proc.the proc.

Use some specially Use some specially crafted SQL to crafted SQL to create usable HTML create usable HTML for your reportsfor your reports

Page 12: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Welcome to the Web Assistant WizardWelcome to the Web Assistant Wizard

Page 13: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Adding FunctionalityAdding Functionality

Use SQL to create usable HTML Use SQL to create usable HTML elementselements Select ‘<input type=checkbox Select ‘<input type=checkbox

name=orderid value=‘ + name=orderid value=‘ + convert(varchar(10),orders.orderid) + ‘ convert(varchar(10),orders.orderid) + ‘ onclick=document.location.href=“orderonclick=document.location.href=“ordersummary.cfm?orderid=‘ + summary.cfm?orderid=‘ + convert(varchar(10),orders.orderid) convert(varchar(10),orders.orderid) +”>+”>

Page 14: Stored Procedures (dynamic Order By + Web Assistant Wizard) Kevin Penny, MMCP kevin@hotgigs.com

Live ExampleLive Example

Adding the SQL to the Stored Adding the SQL to the Stored Procedure that will give the reports Procedure that will give the reports some added usability and functionsome added usability and function

Simple Checkbox with a link to a cfm Simple Checkbox with a link to a cfm pagepage

Ability to ‘regenerate’ the Job via a Ability to ‘regenerate’ the Job via a link (link (EXEC sp_runwebtask EXEC sp_runwebtask @procname = N'Northwind Web @procname = N'Northwind Web Page'Page'))