Your SlideShare is downloading. ×
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Sybase SQL AnyWhere12
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Sybase SQL AnyWhere12

230

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
230
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Sybase SQL AnyWhere 12BySunny Okoro
  • 2. 1ContentsDatabase Platform................................................................................................................................................................... 2Applications............................................................................................................................................................................... 2Database Diagram................................................................................................................................................................ 5Functions..................................................................................................................................................................................... 7User Defined Function.........................................................................................................................................................10Stored Procedures.................................................................................................................................................................11DDL..............................................................................................................................................................................................14Triggers......................................................................................................................................................................................20XML..............................................................................................................................................................................................21Cursors.......................................................................................................................................................................................22DBA..............................................................................................................................................................................................24
  • 3. 2Database PlatformSybase SQLAnyWhere 12ApplicationsSybase CentralSybase PowerDesigner
  • 4. 3Microsoft Excel and Power PivotMicrosoft Visual Studio 2012
  • 5. 4Sybase InfoMaker 11
  • 6. 5Database DiagramCaptured from Sybase PowerDesigner 16
  • 7. 6FK_Store_SalesPerson_SalesPersonIDFK_Store_BusinessEntity_BusinessEntityIDFK_SpecialOfferProduct_SpecialOffer_SpecialOfferIDFK_SpecialOfferProduct_Product_ProductIDFK_ShoppingCartItem_Product_ProductIDFK_SalesTerritoryHistory_SalesTerritory_TerritoryIDFK_SalesTerritoryHistory_SalesPerson_BusinessEntityIDFK_SalesTerritory_CountryRegion_CountryRegionCodeFK_SalesTaxRate_StateProvince_StateProvinceIDFK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityIDFK_SalesPerson_SalesTerritory_TerritoryIDFK_SalesPerson_Employee_BusinessEntityIDFK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderIDFK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonIDFK_SalesOrderHeader_SalesTerritory_TerritoryIDFK_SalesOrderHeader_ShipMethod_ShipMethodIDFK_SalesOrderHeader_SalesPerson_SalesPersonIDFK_SalesOrderHeader_Customer_CustomerIDFK_SalesOrderHeader_CurrencyRate_CurrencyRateIDFK_SalesOrderHeader_CreditCard_CreditCardIDFK_SalesOrderHeader_Address_ShipToAddressIDFK_SalesOrderHeader_Address_BillToAddressIDFK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductIDFK_SalesOrderDetail_SalesOrderHeader_SalesOrderIDFK_PersonCreditCard_CreditCard_CreditCardIDFK_PersonCreditCard_Person_BusinessEntityIDFK_Customer_SalesTerritory_TerritoryIDFK_Customer_Store_StoreIDFK_Customer_Person_PersonIDFK_CurrencyRate_Currency_ToCurrencyCodeFK_CurrencyRate_Currency_FromCurrencyCodeFK_CountryRegionCurrency_Currency_CurrencyCodeFK_CountryRegionCurrency_CountryRegion_CountryRegionCodeFK_Vendor_BusinessEntity_BusinessEntityIDFK_PurchaseOrderHeader_ShipMethod_ShipMethodIDFK_PurchaseOrderHeader_Vendor_VendorIDFK_PurchaseOrderHeader_Employee_EmployeeIDFK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderIDFK_PurchaseOrderDetail_Product_ProductIDFK_ProductVendor_Vendor_BusinessEntityIDFK_ProductVendor_UnitMeasure_UnitMeasureCodeFK_ProductVendor_Product_ProductIDFK_WorkOrderRouting_WorkOrder_WorkOrderIDFK_WorkOrderRouting_Location_LocationIDFK_WorkOrder_ScrapReason_ScrapReasonIDFK_WorkOrder_Product_ProductIDFK_TransactionHistory_Product_ProductIDFK_ProductSubcategory_ProductCategory_ProductCategoryIDFK_ProductReview_Product_ProductIDFK_ProductProductPhoto_ProductPhoto_ProductPhotoIDFK_ProductProductPhoto_Product_ProductIDFK_ProductModelProductDescriptionCulture_ProductModel_ProductModelIDFK_ProductModelProductDescriptionCulture_Culture_CultureIDFK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionIDFK_ProductModelIllustration_Illustration_IllustrationIDFK_ProductModelIllustration_ProductModel_ProductModelIDFK_ProductListPriceHistory_Product_ProductIDFK_ProductInventory_Product_ProductIDFK_ProductInventory_Location_LocationIDFK_ProductDocument_Document_DocumentNodeIDFK_ProductDocument_Product_ProductIDFK_ProductCostHistory_Product_ProductIDFK_Product_ProductSubcategory_ProductSubcategoryIDFK_Product_ProductModel_ProductModelIDFK_Product_UnitMeasure_WeightUnitMeasureCodeFK_Product_UnitMeasure_SizeUnitMeasureCodeFK_Document_Employee_OwnerFK_BillOfMaterials_UnitMeasure_UnitMeasureCodeFK_BillOfMaterials_Product_ComponentIDFK_BillOfMaterials_Product_ProductAssemblyIDFK_StateProvince_SalesTerritory_TerritoryIDFK_StateProvince_CountryRegion_CountryRegionCodeFK_PersonPhone_PhoneNumberType_PhoneNumberTypeIDFK_PersonPhone_Person_BusinessEntityIDFK_Person_BusinessEntity_BusinessEntityIDFK_Password_Person_BusinessEntityIDFK_EmailAddress_Person_BusinessEntityIDFK_BusinessEntityContact_BusinessEntity_BusinessEntityIDFK_BusinessEntityContact_ContactType_ContactTypeIDFK_BusinessEntityContact_Person_PersonID FK_BusinessEntityAddress_BusinessEntity_BusinessEntityIDFK_BusinessEntityAddress_AddressType_AddressTypeIDFK_BusinessEntityAddress_Address_AddressIDFK_Address_StateProvince_StateProvinceIDFK_JobCandidate_Employee_BusinessEntityIDFK_EmployeePayHistory_Employee_BusinessEntityIDFK_EmployeeDepartmentHistory_Shift_ShiftIDFK_EmployeeDepartmentHistory_Employee_BusinessEntityIDFK_EmployeeDepartmentHistory_Department_DepartmentIDFK_Employee_Person_BusinessEntityIDDocumentDocumentNodeIDTitleOwnerFolderFlagFileNameFileExtensionRevisionChangeNumberStatusDocumentSummaryDocumentrowguidModifiedDateintegernvarcharintegerbitnvarcharnvarcharncharintegertinyintnvarcharvarbinary(32767)uniqueidentifiertimestamp<pk><fk><ak>CultureCultureIDNameModifiedDatencharnvarchartimestamp<pk>BillOfMaterialsBillOfMaterialsIDProductAssemblyIDComponentIDStartDateEndDateUnitMeasureCodeBOMLevelPerAssemblyQtyModifiedDateintegerintegerintegertimestamptimestampncharsmallintdecimal(8,2)timestamp<pk><fk1><fk2><fk3>StateProvinceStateProvinceIDStateProvinceCodeCountryRegionCodeIsOnlyStateProvinceFlagNameTerritoryIDrowguidModifiedDateintegerncharnvarcharbitnvarcharintegeruniqueidentifiertimestamp<pk><fk1><fk2>PhoneNumberTypePhoneNumberTypeIDNameModifiedDateintegernvarchartimestamp<pk>PersonPhoneBusinessEntityIDPhoneNumberPhoneNumberTypeIDModifiedDateintegernvarcharintegertimestamp<pk,fk1><pk><pk,fk2>PersonBusinessEntityIDPersonTypeNameStyleTitleFirstNameMiddleNameLastNameSuffixEmailPromotionAdditionalContactInfoDemographicsrowguidModifiedDateintegerncharbitnvarcharnvarcharnvarcharnvarcharnvarcharintegerxmlxmluniqueidentifiertimestamp<pk,fk>PasswordBusinessEntityIDPasswordHashPasswordSaltrowguidModifiedDateintegervarchar(128)varchar(10)uniqueidentifiertimestamp<pk,fk>EmailAddressBusinessEntityIDEmailAddressIDEmailAddressrowguidModifiedDateintegerintegernvarcharuniqueidentifiertimestamp<pk,fk><pk>CountryRegionCountryRegionCodeNameModifiedDatenvarcharnvarchartimestamp<pk>ContactTypeContactTypeIDNameModifiedDateintegernvarchartimestamp<pk>BusinessEntityContactBusinessEntityIDPersonIDContactTypeIDrowguidModifiedDateintegerintegerintegeruniqueidentifiertimestamp<pk,fk3><pk,fk1><pk,fk2> BusinessEntityAddressBusinessEntityIDAddressIDAddressTypeIDrowguidModifiedDateintegerintegerintegeruniqueidentifiertimestamp<pk,fk3><pk,fk1><pk,fk2>BusinessEntityBusinessEntityIDrowguidModifiedDateintegeruniqueidentifiertimestamp<pk>AddressTypeAddressTypeIDNamerowguidModifiedDateintegernvarcharuniqueidentifiertimestamp<pk>AddressAddressIDAddressLine1AddressLine2CityStateProvinceIDPostalCodeSpatialLocationrowguidModifiedDateintegernvarcharnvarcharnvarcharintegernvarcharst_geometry(32767)uniqueidentifiertimestamp<pk><fk>ShiftShiftIDNameStartTimeEndTimeModifiedDatetinyintnvarchartimetimetimestamp<pk>JobCandidateJobCandidateIDBusinessEntityIDResumeModifiedDateintegerintegerxmltimestamp<pk><fk>EmployeePayHistoryBusinessEntityIDRateChangeDateRatePayFrequencyModifiedDateintegertimestampnumeric(19,4)tinyinttimestamp<pk,fk><pk>EmployeeDepartmentHistoryBusinessEntityIDDepartmentIDShiftIDStartDateEndDateModifiedDateintegersmallinttinyintdatedatetimestamp<pk,fk2><pk,fk1><pk,fk3><pk>EmployeeBusinessEntityIDNationalIDNumberLoginIDJobTitleBirthDateMaritalStatusGenderHireDateSalariedFlagVacationHoursSickLeaveHoursCurrentFlagrowguidModifiedDateintegernvarcharnvarcharnvarchardatencharnchardatebitsmallintsmallintbituniqueidentifiertimestamp<pk,fk>DepartmentDepartmentIDNameGroupNameModifiedDatesmallintnvarcharnvarchartimestamp<pk>IllustrationIllustrationIDDiagramModifiedDateintegerxmltimestamp<pk>LocationLocationIDNameCostRateAvailabilityModifiedDatesmallintnvarcharnumeric(10,4)decimal(8,2)timestamp<pk>ProductProductIDProductNumberMakeFlagFinishedGoodsFlagNameColorSafetyStockLevelReorderPointListPriceSizeSizeUnitMeasureCodeStandardCostWeightUnitMeasureCodeWeightDaysToManufactureProductLineClassStyleProductSubcategoryIDProductModelIDSellStartDateSellEndDateDiscontinuedDaterowguidModifiedDateintegernvarcharbitbitnvarcharnvarcharsmallintsmallintnumeric(19,4)nvarcharncharnumeric(19,4)nchardecimal(8,2)integerncharncharncharintegerintegertimestamptimestamptimestampuniqueidentifiertimestamp<pk><fk1><fk2><fk4><fk3>ProductCategoryProductCategoryIDNamerowguidModifiedDateintegernvarcharuniqueidentifiertimestamp<pk>ProductCostHistoryProductIDStartDateEndDateStandardCostModifiedDateintegertimestamptimestampnumeric(19,4)timestamp<pk,fk><pk>ProductDescriptionProductDescriptionIDDescriptionrowguidModifiedDateintegernvarcharuniqueidentifiertimestamp<pk>ProductDocumentProductIDDocumentNodeIDModifiedDateintegerintegertimestamp<pk,fk1><pk,fk2>ProductInventoryProductIDLocationIDShelfBinQuantityrowguidModifiedDateintegersmallintnvarchartinyintsmallintuniqueidentifiertimestamp<pk,fk2><pk,fk1>ProductListPriceHistoryProductIDStartDateEndDateListPriceModifiedDateintegertimestamptimestampnumeric(19,4)timestamp<pk,fk><pk>ProductModelProductModelIDNameCatalogDescriptionInstructionsrowguidModifiedDateintegernvarcharxmlxmluniqueidentifiertimestamp<pk>ProductModelIllustrationProductModelIDIllustrationIDModifiedDateintegerintegertimestamp<pk,fk1><pk,fk2>ProductModelProductDescriptionCultureProductModelIDProductDescriptionIDCultureIDModifiedDateintegerintegernchartimestamp<pk,fk3><pk,fk1><pk,fk2>ProductPhotoProductPhotoIDThumbNailPhotoThumbnailPhotoFileNameLargePhotoLargePhotoFileNameModifiedDateintegervarbinary(32767)nvarcharvarbinary(32767)nvarchartimestamp<pk>ProductProductPhotoProductIDProductPhotoIDPrimaryModifiedDateintegerintegerbittimestamp<pk,fk1><pk,fk2>ProductReviewProductReviewIDProductIDReviewerNameReviewDateEmailAddressRatingCommentsModifiedDateintegerintegernvarchartimestampnvarcharintegernvarchartimestamp<pk><fk>ProductSubcategoryProductSubcategoryIDProductCategoryIDNamerowguidModifiedDateintegerintegernvarcharuniqueidentifiertimestamp<pk><fk>ScrapReasonScrapReasonIDNameModifiedDatesmallintnvarchartimestamp<pk>TransactionHistoryTransactionIDProductIDReferenceOrderIDReferenceOrderLineIDTransactionDateTransactionTypeQuantityActualCostModifiedDateintegerintegerintegerintegertimestampncharintegernumeric(19,4)timestamp<pk><fk>UnitMeasureUnitMeasureCodeNameModifiedDatencharnvarchartimestamp<pk>WorkOrderWorkOrderIDProductIDOrderQtyStockedQtyScrappedQtyStartDateEndDateDueDateScrapReasonIDModifiedDateintegerintegerintegerintegersmallinttimestamptimestamptimestampsmallinttimestamp<pk><fk1><fk2>WorkOrderRoutingWorkOrderIDProductIDOperationSequenceLocationIDScheduledStartDateScheduledEndDateActualStartDateActualEndDateActualResourceHrsPlannedCostActualCostModifiedDateintegerintegersmallintsmallinttimestamptimestamptimestamptimestampdecimal(9,4)numeric(19,4)numeric(19,4)timestamp<pk,fk2><pk><pk><fk1>ProductVendorProductIDBusinessEntityIDAverageLeadTimeStandardPriceLastReceiptCostLastReceiptDateMinOrderQtyMaxOrderQtyOnOrderQtyUnitMeasureCodeModifiedDateintegerintegerintegernumeric(19,4)numeric(19,4)timestampintegerintegerintegernchartimestamp<pk,fk1><pk,fk3><fk2>PurchaseOrderDetailPurchaseOrderIDPurchaseOrderDetailIDDueDateOrderQtyProductIDUnitPriceLineTotalReceivedQtyRejectedQtyStockedQtyModifiedDateintegerintegertimestampsmallintintegernumeric(19,4)numeric(19,4)decimal(8,2)decimal(8,2)decimaltimestamp<pk,fk2><pk><fk1>PurchaseOrderHeaderPurchaseOrderIDRevisionNumberStatusEmployeeIDVendorIDShipMethodIDOrderDateShipDateSubTotalTaxAmtFreightTotalDueModifiedDateintegertinyinttinyintintegerintegerintegertimestamptimestampnumeric(19,4)numeric(19,4)numeric(19,4)numeric(19,4)timestamp<pk><fk1><fk2><fk3>ShipMethodShipMethodIDNameShipBaseShipRaterowguidModifiedDateintegernvarcharnumeric(19,4)numeric(19,4)uniqueidentifiertimestamp<pk>VendorBusinessEntityIDAccountNumberNameCreditRatingPreferredVendorStatusActiveFlagPurchasingWebServiceURLModifiedDateintegernvarcharnvarchartinyintbitbitnvarchartimestamp<pk,fk>CountryRegionCurrencyCountryRegionCodeCurrencyCodeModifiedDatenvarcharnchartimestamp<pk,fk1><pk,fk2>CreditCardCreditCardIDCardTypeCardNumberExpMonthExpYearModifiedDateintegernvarcharnvarchartinyintsmallinttimestamp<pk>CurrencyCurrencyCodeNameModifiedDatencharnvarchartimestamp<pk>CurrencyRateCurrencyRateIDCurrencyRateDateFromCurrencyCodeToCurrencyCodeAverageRateEndOfDayRateModifiedDateintegertimestampncharncharnumeric(19,4)numeric(19,4)timestamp<pk><fk1><fk2>CustomerCustomerIDPersonIDStoreIDTerritoryIDAccountNumberrowguidModifiedDateintegerintegerintegerintegervarchar(10)uniqueidentifiertimestamp<pk><fk1><fk2><fk3>PersonCreditCardBusinessEntityIDCreditCardIDModifiedDateintegerintegertimestamp<pk,fk1><pk,fk2>SalesOrderDetailSalesOrderIDSalesOrderDetailIDCarrierTrackingNumberOrderQtyProductIDSpecialOfferIDUnitPriceUnitPriceDiscountLineTotalrowguidModifiedDateintegerintegernvarcharsmallintintegerintegernumeric(19,4)numeric(19,4)numeric(19,4)uniqueidentifiertimestamp<pk,fk1><pk><fk2><fk2>SalesOrderHeaderSalesOrderIDRevisionNumberOrderDateDueDateShipDateStatusOnlineOrderFlagSalesOrderNumberShipMethodIDPurchaseOrderNumberAccountNumberCustomerIDSalesPersonIDTerritoryIDBillToAddressIDShipToAddressIDCreditCardIDCreditCardApprovalCodeCurrencyRateIDSubTotalTaxAmtFreightTotalDueCommentrowguidModifiedDateintegertinyinttimestamptimestamptimestamptinyintbitnvarcharintegernvarcharnvarcharintegerintegerintegerintegerintegerintegervarchar(15)integernumeric(19,4)numeric(19,4)numeric(19,4)numeric(19,4)nvarcharuniqueidentifiertimestamp<pk><fk7><fk5><fk6><fk8><fk1><fk2><fk3><fk4>SalesOrderHeaderSalesReasonSalesOrderIDSalesReasonIDModifiedDateintegerintegertimestamp<pk,fk2><pk,fk1>SalesPersonBusinessEntityIDTerritoryIDSalesQuotaBonusCommissionPctSalesYTDSalesLastYearrowguidModifiedDateintegerintegernumeric(19,4)numeric(19,4)numeric(10,4)numeric(19,4)numeric(19,4)uniqueidentifiertimestamp<pk,fk1><fk2>SalesPersonQuotaHistoryBusinessEntityIDQuotaDateSalesQuotarowguidModifiedDateintegertimestampnumeric(19,4)uniqueidentifiertimestamp<pk,fk><pk>SalesReasonSalesReasonIDNameReasonTypeModifiedDateintegernvarcharnvarchartimestamp<pk>SalesTaxRateSalesTaxRateIDStateProvinceIDTaxTypeTaxRateNamerowguidModifiedDateintegerintegertinyintnumeric(10,4)nvarcharuniqueidentifiertimestamp<pk><fk>SalesTerritoryTerritoryIDNameCountryRegionCodeGroupSalesYTDSalesLastYearCostYTDCostLastYearrowguidModifiedDateintegernvarcharnvarcharnvarcharnumeric(19,4)numeric(19,4)numeric(19,4)numeric(19,4)uniqueidentifiertimestamp<pk><fk>SalesTerritoryHistoryBusinessEntityIDTerritoryIDStartDateEndDaterowguidModifiedDateintegerintegertimestamptimestampuniqueidentifiertimestamp<pk,fk1><pk,fk2><pk>ShoppingCartItemShoppingCartItemIDShoppingCartIDQuantityProductIDDateCreatedModifiedDateintegernvarcharintegerintegertimestamptimestamp<pk><fk>SpecialOfferSpecialOfferIDDescriptionDiscountPctTypeCategoryStartDateEndDateMinQtyMaxQtyrowguidModifiedDateintegernvarcharnumeric(10,4)nvarcharnvarchartimestamptimestampintegerintegeruniqueidentifiertimestamp<pk>SpecialOfferProductSpecialOfferIDProductIDrowguidModifiedDateintegerintegeruniqueidentifiertimestamp<pk,fk2><pk,fk1>StoreBusinessEntityIDNameSalesPersonIDDemographicsrowguidModifiedDateintegernvarcharintegerxmluniqueidentifiertimestamp<pk,fk1><fk2>
  • 8. 7FunctionsSELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, convert (date, soh.DueDate) as DueDate, cast (soh.ShipDate as date) as ShipDate, soh.SalesOrderNumber,soh.PurchaseOrderNumber,soh.TerritoryID,soh.ShipMethodID, soh.CreditCardID,soh.SubTotal, soh.Freight, soh.TaxAmt, soh.TotalDue, dateformat( soh.OrderDate,MM-DD-YYYY)as OrderDateFROM Sales.Customer cinner joinSales.SalesOrderHeader sohon c.CustomerID = soh.CustomerIDinner joinSales.SalesOrderDetail sodon soh.SalesOrderID = sod.SalesOrderIDCustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID CreditCardID SubTotal Freight TaxAmt TotalDue OrderDate29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-200129825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-200129825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-200129825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-200129825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001Results AbridgedSELECT string(LastName, FirstName) AS Person_Name, lastName||,||firstName as Person_Name2FROM Person.PersonPerson_Name Person_Name2SánchezKen Sánchez,KenDuffyTerri Duffy,TerriTamburelloRoberto Tamburello,RobertoWaltersRob Walters,RobEricksonGail Erickson,GailGoldbergJossef Goldberg,JossefResults AbridgedSELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, convert (date, soh.DueDate) as DueDate, cast (soh.ShipDate as date) as ShipDate, soh.SalesOrderNumber,soh.PurchaseOrderNumber,soh.TerritoryID,soh.ShipMethodID,soh.SubTotal, soh.Freight, soh.TaxAmt, soh.TotalDue,year( soh.OrderDate) ||-|| monthname( soh.OrderDate) ||-|| day( soh.OrderDate) ||-||dayname( soh.OrderDate)||,|| quarter( soh.OrderDate) as OrderDateFROM Sales.Customer cinner joinSales.SalesOrderHeader sohon c.CustomerID = soh.CustomerIDinner joinSales.SalesOrderDetail sodon soh.SalesOrderID = sod.SalesOrderIDCustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID SubTotal Freight TaxAmt TotalDue OrderDate29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,329672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,329672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,329734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,329734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,329734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,329734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,329734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3Results AbridgedSELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, convert (date, soh.DueDate) as DueDate, cast (soh.ShipDate as date) as ShipDate, soh.SalesOrderNumber,soh.PurchaseOrderNumber,j.Name as TerritoryName, soh.ShipMethodID,cast( soh.SubTotal as decimal(35,2))as Subtotal, cast( soh.Freight as decimal(35,2))as Freight, cast(soh.TaxAmt as decimal(35,2))as TaxAmt , cast (soh.TotalDue as decimal(35,2)) as TotalDue2 , soh.TotalDue,year( soh.OrderDate) ||-|| monthname( soh.OrderDate) ||-|| day( soh.OrderDate) ||-||dayname( soh.OrderDate)||,|| quarter( soh.OrderDate) as OrderDateFROM Sales.Customer cinner joinSales.SalesOrderHeader soh
  • 9. 8on c.CustomerID = soh.CustomerIDinner joinSales.SalesOrderDetail sodon soh.SalesOrderID = sod.SalesOrderIDinner join Sales.SalesTerritory jonsoh.TerritoryID = j.TerritoryIDCustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryName ShipMethodID Subtotal Freight TaxAmt TotalDue2 TotalDue OrderDate29614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329614 AW00029614 43668 2001-07-13 2001-07-08 SO43668 PO14732180295 Canada 5 43272.07 1081.80 3461.77 47815.63 47815.6341 2001-July-1-Sunday,329747 AW00029747 43669 2001-07-13 2001-07-08 SO43669 PO14123169936 Northwest 5 881.47 22.04 70.52 974.02 974.0229 2001-July-1-Sunday,329566 AW00029566 43670 2001-07-13 2001-07-08 SO43670 PO14384116310 Central 5 7344.50 183.61 587.56 8115.68 8115.6763 2001-July-1-Sunday,329566 AW00029566 43670 2001-07-13 2001-07-08 SO43670 PO14384116310 Central 5 7344.50 183.61 587.56 8115.68 8115.6763 2001-July-1-Sunday,329566 AW00029566 43670 2001-07-13 2001-07-08 SO43670 PO14384116310 Central 5 7344.50 183.61 587.56 8115.68 8115.6763 2001-July-1-Sunday,329566 AW00029566 43670 2001-07-13 2001-07-08 SO43670 PO14384116310 Central 5 7344.50 183.61 587.56 8115.68 8115.6763 2001-July-1-Sunday,329890 AW00029890 43671 2001-07-13 2001-07-08 SO43671 PO13978119376 Northwest 5 9760.17 244.00 780.81 10784.99 10784.9873 2001-July-1-Sunday,329890 AW00029890 43671 2001-07-13 2001-07-08 SO43671 PO13978119376 Northwest 5 9760.17 244.00 780.81 10784.99 10784.9873 2001-July-1-Sunday,329890 AW00029890 43671 2001-07-13 2001-07-08 SO43671 PO13978119376 Northwest 5 9760.17 244.00 780.81 10784.99 10784.9873 2001-July-1-Sunday,3Results AbridgedSELECT string(LastName, FirstName) AS Person_Name, UPPER (lastName)||,|| LOWER(firstName) as Person_Name2FROM Person.PersonPerson_Name Person_Name2SánchezKen SÁNCHEZ,kenDuffyTerri DUFFY,terriTamburelloRoberto TAMBURELLO,robertoWaltersRob WALTERS,robEricksonGail ERICKSON,gailGoldbergJossef GOLDBERG,jossefMillerDylan MILLER,dylanMargheimDiane MARGHEIM,dianeMatthewGigi MATTHEW,gigiRaheemMichael RAHEEM,michaelCraciumOvidiu CRACIUM,ovidiuDHersThierry DHERS,thierryGalvinJanice GALVIN,janiceSullivanMichael SULLIVAN,michaelSalavariaSharon SALAVARIA,sharonBradleyDavid BRADLEY,davidBrownKevin BROWN,kevinWoodJohn WOOD,johnDempseyMary DEMPSEY,maryBenshoofWanida BENSHOOF,wanidaEminhizerTerry EMINHIZER,terryHarnpadoungsatayaSariya HARNPADOUNGSATAYA,sariyaResults AbridgedWITH ORDERS4(CUSTOMER_ID,TOTAL_DUE)AS(SELECT CUSTOMERID AS CUSTOMER_ID, TotalDue AS TOTAL_DUEFROM ORDERS)SELECT DISTINCT (CUSTOMER_ID)as CUSTOMER_ID, cast(TOTAL_DUE as decimal (23,2))as TOTAL_DUEFROMORDERS4WHERE TOTAL_DUE <> (SELECT cast (max(TotalDue)as decimal (23,2)) FROM ORDERS)CUSTOMER_ID TOTAL_DUE29825 27231.5529672 1716.1829734 43561.4429994 38331.9629565 556.2029898 32390.2029580 19005.2130052 6718.0529974 8095.7929614 47815.6329747 974.0229566 8115.6829890 10784.99Results AbridgedSELECT HRE.BusinessEntityID, HRE.BirthDate, HRE.Gender, HRE.MaritalStatus, HRE.NationalIDNumber,HRE.SickLeaveHours, HRE.VacationHours,DATEDIFF(YY, BirthDate , CURRENT_TIMESTAMP) AS AGE
  • 10. 9FROM HumanResources.Employee HREBusinessEntityID BirthDate Gender MaritalStatus NationalIDNumber SickLeaveHours VacationHours AGE1 1959-03-02 M S 295847284 69 99 542 1961-09-01 F S 245797967 20 1 523 1964-12-13 M M 509647174 21 2 494 1965-01-23 M S 112457891 80 48 485 1942-10-29 F M 695256908 22 5 716 1949-04-11 M M 998320692 23 6 647 1977-03-27 M M 134969118 50 61 368 1976-07-06 F S 811994146 51 62 379 1969-02-21 F M 658797903 51 63 4410 1975-01-01 M M 879342154 64 16 3811 1968-02-18 M S 974026903 23 7 4512 1949-08-29 M M 480168528 24 9 6413 1979-06-29 F M 486228782 24 8 3414 1969-07-17 M S 42487730 21 3 4415 1951-06-03 F M 56920285 22 4 6216 1965-04-19 M S 24756624 40 40 4817 1977-06-03 M S 253022876 41 42 36Results AbridgedSELECT SOH.CustomerID, CAST (SOH.OrderDate AS DATE)OrderDate, SOH.SalesOrderID,CAST(SOH.Freight AS DECIMAL(30,2))AS Freight, CAST(SOH.TaxAmt AS DECIMAL(30,2))AS TaxAmt,CAST(SOH.TotalDue AS DECIMAL(30,2))AS TotalDue,SCC.CardType, encrypt(SCC.CardNumber, AES256) AS CardNum, SCC.ExpMonth||-||SCC.ExpYear AS EXP_DATE,SCY.Name AS Currency_Name, STR.CountryRegionCode, STR.Name AS Territory_Name, STR."Group" AS TerritoryGroupFROM Sales.SalesOrderHeader SOHINNER JOINSales.Customer SCONSOH. CUSTOMERID = SC.CUSTOMERIDINNER JOINSales.CreditCard SCCONSCC.CREDITCARDID = SOH.CREDITCARDIDINNER JOINSALES.CurrencyRate SCRONSOH.CurrencyRateID = SCR.CurrencyRateIDINNER JOINSALES.SalesTerritory STRONSTR.TerritoryID = SOH.TerritoryIDINNER JOINSALES.Currency SCYONSCY.CurrencyCode = SCR.FromCurrencyCodeORSCY.CurrencyCode = SCR.ToCurrencyCodeCustomerID OrderDate SalesOrderID Freight TaxAmt TotalDue CardType CardNum EXP_DATE Currency_Name CountryRegionCode Territory_Name TerritoryGroup29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 US Dollar CA Canada North America29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 Canadian Dollar CA Canada North America29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 US Dollar CA Canada North America29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 Canadian Dollar CA Canada North America29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 US Dollar CA Canada North America29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 Canadian Dollar CA Canada North America30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 US Dollar CA Canada North America30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 Canadian Dollar CA Canada North America29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 US Dollar CA Canada North America29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 Canadian Dollar CA Canada North America29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 US Dollar CA Canada North America29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 Canadian Dollar CA Canada North America29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 US Dollar CA Canada North America29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 Canadian Dollar CA Canada North America21768 2001-07-01 43697 89.46 286.26 3953.99 SuperiorCard 0x477e43dc99fc3fc8e8dc127b735cf3c51b37b17addfb8f0064d3e3c2fffc0d0e 7-2008 US Dollar CA Canada North AmericaResults AbridgedSELECT SOH.SalesOrderID, SOH.CustomerID,CAST(SOH.TotalDue AS DECIMAL(30,2))AS TotalDue,STR.CountryRegionCode, STR.Name AS Territory_Name, STR."Group" AS TerritoryGroup,SUM(CAST(SOH.TotalDue AS DECIMAL(30,2)))over(PARTITION BY STR.CountryRegionCode) AS TOTAL_Territor_Sales_Region,SUM(CAST(SOH.TotalDue AS DECIMAL(30,2)))over(PARTITION BY STR."Group") AS TOTAL_Territor_Sales_Group,SUM(CAST(SOH.TotalDue AS DECIMAL(30,2)))over(PARTITION BY STR.Name) AS TOTAL_Territor_Sales_NameFROM Sales.SalesOrderHeader SOHINNER JOINSALES.SalesTerritory STRONSTR.TerritoryID = SOH.TerritoryIDwhere STR.CountryRegionCode = US
  • 11. 10SalesOrderID CustomerID TotalDue CountryRegionCode Territory_Name TerritoryGroup TOTAL_Territor_Sales_Region TOTAL_Territor_Sales_Group TOTAL_Territor_Sales_Name66560 21246 1320.44 US Southwest North America 82425339.37 82425339.37 31213458.7170656 24831 2649.85 US Southwest North America 82425339.37 82425339.37 31213458.7170912 17441 2657.47 US Southwest North America 82425339.37 82425339.37 31213458.7144544 29522 27847.06 US Southwest North America 82425339.37 82425339.37 31213458.7145568 29637 20205.63 US Southwest North America 82425339.37 82425339.37 31213458.7146336 29944 556.20 US Southwest North America 82425339.37 82425339.37 31213458.7147104 13279 2410.63 US Southwest North America 82425339.37 82425339.37 31213458.7147360 29696 1051.23 US Southwest North America 82425339.37 82425339.37 31213458.7148128 26534 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.7148384 29562 90625.93 US Southwest North America 82425339.37 82425339.37 31213458.7148640 26681 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.7149152 29792 30842.05 US Southwest North America 82425339.37 82425339.37 31213458.7149408 15535 865.20 US Southwest North America 82425339.37 82425339.37 31213458.7150688 29793 77584.01 US Southwest North America 82425339.37 82425339.37 31213458.7151968 13171 132.60 US Southwest North America 82425339.37 82425339.37 31213458.7155296 29850 2916.30 US Southwest North America 82425339.37 82425339.37 31213458.7157344 12047 38.68 US Southwest North America 82425339.37 82425339.37 31213458.7158368 25208 30.14 US Southwest North America 82425339.37 82425339.37 31213458.7160160 13454 2590.41 US Southwest North America 82425339.37 82425339.37 31213458.71Results AbridgedUser Defined FunctionCREATE OR REPLACE FUNCTION EMPAGE( )RETURNS INTEGERBEGINSELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGEFROM HumanResources.Employee HREEND;SELECT SELECT "DBA"."EMPAGE"();CREATE OR REPLACE FUNCTION EMPAGE( in @SNN integer)RETURNS INTEGERBEGINDECLARE @EMPAGE1 integer;SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGEINTO@EMPAGE1FROM HumanResources.Employee HREWHERE HRE.NationalIDNumber = @SNN;RETURN (@EMPAGE1);END;SELECT "DBA"."EMPAGE"(509647174 ) AS EMP_AGE;
  • 12. 11Stored ProceduresCREATE OR REPLACE PROCEDURE SalesTerritory_Report(@Region_Code Char(8))ASSELECT SOH.SalesOrderNumber, CAST (SOH.OrderDate AS DATE) AS OrderDate , CAST (SOH.DueDate AS DATE) AS DueDate, CAST (SOH.ShipDate AS DATE) AS ShipDate, SOD.ProductID,SOH.CUSTOMERID AS CustomerID, cast (SOH.SUBTOTAL as Decimal (35,2))AS SubTotal,cast (SOH.TAXAMT as Decimal (35,2))AS TaxAmt, cast (SOH.FREIGHT as Decimal (35,2))AS Freight, cast (SOH.TOTALDUE as Decimal (35,2))AS TotalDue, PD.Name AS ProductName, ST.NAME as TerritoryName,ST.CountryRegionCode,ST."Group" AS TerritoryGroup, ST.TerritoryIDFROM Sales.SalesOrderDetail SODINNER JOIN Sales.SalesOrderHeader SOHONSOD.SalesOrderID = SOH.SalesOrderIDINNER JOIN Production.Product PDON SOD.PRODUCTID = PD.PRODUCTIDINNER JOINSALES.SalesTerritory STONSOH.TerritoryID = ST.TerritoryIDwhere CountryRegionCode = @Region_CodeORDER BY PD.NAME;EXEC SalesTerritory_Report(GB)SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryIDSO73803 2004-06-26 2004-07-08 2004-07-03 879 16938 928.49 74.28 23.21 1025.98 All-Purpose Bike Stand United Kingdom GB Europe 10SO70784 2004-05-17 2004-05-29 2004-05-24 879 14156 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO71313 2004-05-25 2004-06-06 2004-06-01 879 16325 166.28 13.30 4.16 183.74 All-Purpose Bike Stand United Kingdom GB Europe 10SO74525 2004-07-12 2004-07-24 2004-07-19 879 13830 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO69201 2004-04-28 2004-05-10 2004-05-05 879 25482 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10SO69205 2004-04-28 2004-05-10 2004-05-05 879 13664 195.27 15.62 4.88 215.77 All-Purpose Bike Stand United Kingdom GB Europe 10SO55484 2003-10-03 2003-10-15 2003-10-10 879 17840 188.98 15.12 4.72 208.82 All-Purpose Bike Stand United Kingdom GB Europe 10SO60357 2003-12-19 2003-12-31 2003-12-26 879 12513 182.78 14.62 4.57 201.97 All-Purpose Bike Stand United Kingdom GB Europe 10SO57657 2003-11-09 2003-11-21 2003-11-16 879 25470 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10SO64640 2004-02-21 2004-03-04 2004-02-28 879 12496 204.58 16.37 5.11 226.06 All-Purpose Bike Stand United Kingdom GB Europe 10SO62727 2004-01-25 2004-02-06 2004-02-01 879 21847 187.98 15.04 4.70 207.72 All-Purpose Bike Stand United Kingdom GB Europe 10SO56027 2003-10-13 2003-10-25 2003-10-20 879 20054 2638.94 211.12 65.97 2916.03 All-Purpose Bike Stand United Kingdom GB Europe 10SO59644 2003-12-08 2003-12-20 2003-12-15 879 26938 722.77 57.82 18.07 798.66 All-Purpose Bike Stand United Kingdom GB Europe 10SO57775 2003-11-11 2003-11-23 2003-11-18 879 29373 184.48 14.76 4.61 203.85 All-Purpose Bike Stand United Kingdom GB Europe 10SO64183 2004-02-15 2004-02-27 2004-02-22 879 16589 2481.28 198.50 62.03 2741.81 All-Purpose Bike Stand United Kingdom GB Europe 10Results AbridgedCREATE OR REPLACE PROCEDURE PRODUCTS()ASSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PPD.Description,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPD
  • 13. 12Inner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHexec PRODUCTS;ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name680 HL Road Frame - Black, 58 Black 58 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames706 HL Road Frame - Red, 58 Red 58 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames707 Sport-100 Helmet, Red Red Universal fit, well-vented, lightweight , snap-on visor. Helmets708 Sport-100 Helmet, Black Black Universal fit, well-vented, lightweight , snap-on visor. Helmets709 Mountain Bike Socks, M White M Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks710 Mountain Bike Socks, L White L Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks711 Sport-100 Helmet, Blue Blue Universal fit, well-vented, lightweight , snap-on visor. Helmets712 AWC Logo Cap Multi Traditional style with a flip-up brim; one-size fits all. Caps713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys717 HL Road Frame - Red, 62 Red 62 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames718 HL Road Frame - Red, 44 Red 44 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames719 HL Road Frame - Red, 48 Red 48 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames720 HL Road Frame - Red, 52 Red 52 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road Frames721 HL Road Frame - Red, 56 Red 56 CM Our lightest and best quality aluminum frame made from the newest alloy; it is welded and heat-treated for strength. Our innovative design results in maximum comfort and performance. Road FramesResults AbridgedCREATE OR REPLACE PROCEDURE PRODUCTS2(@sub_catgo_name char(35))ASSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PPD.Description,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PSC.NAME = @sub_catgo_name;Exec PRODUCTS2( ‘Jerseys’);ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys881 Short-Sleeve Classic Jersey, S Yellow S Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys882 Short-Sleeve Classic Jersey, M Yellow M Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys883 Short-Sleeve Classic Jersey, L Yellow L Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys884 Short-Sleeve Classic Jersey, XL Yellow XL Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys/* Sybase Watcon SQL Syntax*/CREATE OR REPLACE PROCEDURE SALES_TERRITORY_GB(
  • 14. 13in @COUNTRYCODE char(8))RESULT(SalesOrderNumber NVARCHAR(25),AccountNumber VARCHAR (10),OrderDate DATE ,DueDate DATE,ShipDate DATE,ProductID INTEGER,CustomerID INTEGER,SubTotal DECIMAL(35,2),TaxAmt DECIMAL (35,2),Freight DECIMAL(35,2),TotalDue DECIMAL(32,2),PRODUCTNAME NAME,"Description" NVARCHAR(400),COLOR NVARCHAR (15),"Size" NVARCHAR(5),SizeUnitMeasureCode NVARCHAR (3),SubCatgoName NAME,ProductSubcategoryID INTEGER,CategoryName NAME,ProductCategoryID INTEGER ,TerritoryName NAME,CountryRegionCode NVARCHAR (3),TerritoryGroup NVARCHAR (50),TerritoryID INTEGER )--on exception resume--beginCASE WHEN @COUNTRYCODE = GBTHENselect SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,CustomerID,SubTotal,TaxAmt,Freight,TotalDue,PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryIDfrom SalesReportswhere CountryRegionCode = @COUNTRYCODEEND CASE;EndEXEC SALES_TERRITORY_GB(US)Execution time: 0.064 secondsEXEC SALES_TERRITORY_GB(UK)SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryIDSO73803 2004-06-26 2004-07-08 2004-07-03 879 16938 928.49 74.28 23.21 1025.98 All-Purpose Bike Stand United Kingdom GB Europe 10SO70784 2004-05-17 2004-05-29 2004-05-24 879 14156 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO71313 2004-05-25 2004-06-06 2004-06-01 879 16325 166.28 13.30 4.16 183.74 All-Purpose Bike Stand United Kingdom GB Europe 10SO74525 2004-07-12 2004-07-24 2004-07-19 879 13830 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO69201 2004-04-28 2004-05-10 2004-05-05 879 25482 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10SO69205 2004-04-28 2004-05-10 2004-05-05 879 13664 195.27 15.62 4.88 215.77 All-Purpose Bike Stand United Kingdom GB Europe 10SO55484 2003-10-03 2003-10-15 2003-10-10 879 17840 188.98 15.12 4.72 208.82 All-Purpose Bike Stand United Kingdom GB Europe 10SO60357 2003-12-19 2003-12-31 2003-12-26 879 12513 182.78 14.62 4.57 201.97 All-Purpose Bike Stand United Kingdom GB Europe 10SO57657 2003-11-09 2003-11-21 2003-11-16 879 25470 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10Results AbridgedCREATE OR REPLACE PROCEDURE SALES_TERRITORY_GB(in @COUNTRYCODE char(8),OUT SalesOrderNumber NVARCHAR(25),OUT AccountNumber VARCHAR (10),OUT OrderDate DATE ,OUT DueDate DATE,OUT ShipDate DATE,OUT ProductID INTEGER,OUT CustomerID INTEGER,OUT SubTotal DECIMAL(35,2),OUT TaxAmt DECIMAL (35,2),OUT Freight DECIMAL(35,2),OUT TotalDue DECIMAL(32,2),OUT PRODUCTNAME NAME,OUT "Description" NVARCHAR(400),OUT COLOR NVARCHAR (15),OUT "Size" NVARCHAR(5),OUT SizeUnitMeasureCode NVARCHAR (3),OUT SubCatgoName NAME,OUT ProductSubcategoryID INTEGER,OUT CategoryName NAME,OUT ProductCategoryID INTEGER ,OUT TerritoryName NAME,OUT CountryRegionCode NVARCHAR (3),OUT TerritoryGroup NVARCHAR (50),OUT TerritoryID INTEGER )--on exception resume--beginCASE WHEN @COUNTRYCODE = GBTHENselect SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,CustomerID,SubTotal,TaxAmt,Freight,TotalDue,PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryIDfrom SalesReportswhere CountryRegionCode = @COUNTRYCODEEND CASE;EndSalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryIDSO73803 2004-06-26 2004-07-08 2004-07-03 879 16938 928.49 74.28 23.21 1025.98 All-Purpose Bike Stand United Kingdom GB Europe 10
  • 15. 14SO70784 2004-05-17 2004-05-29 2004-05-24 879 14156 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO71313 2004-05-25 2004-06-06 2004-06-01 879 16325 166.28 13.30 4.16 183.74 All-Purpose Bike Stand United Kingdom GB Europe 10SO74525 2004-07-12 2004-07-24 2004-07-19 879 13830 195.59 15.65 4.89 216.13 All-Purpose Bike Stand United Kingdom GB Europe 10SO69201 2004-04-28 2004-05-10 2004-05-05 879 25482 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10SO69205 2004-04-28 2004-05-10 2004-05-05 879 13664 195.27 15.62 4.88 215.77 All-Purpose Bike Stand United Kingdom GB Europe 10SO55484 2003-10-03 2003-10-15 2003-10-10 879 17840 188.98 15.12 4.72 208.82 All-Purpose Bike Stand United Kingdom GB Europe 10SO60357 2003-12-19 2003-12-31 2003-12-26 879 12513 182.78 14.62 4.57 201.97 All-Purpose Bike Stand United Kingdom GB Europe 10SO57657 2003-11-09 2003-11-21 2003-11-16 879 25470 162.99 13.04 4.07 180.10 All-Purpose Bike Stand United Kingdom GB Europe 10Results AbridgedDDLCREATE VIEW ORDERSASSELECT c.CustomerID, c.AccountNumber, soh.SalesOrderID, convert (date, soh.DueDate) as DueDate, cast (soh.ShipDate as date) as ShipDate, soh.SalesOrderNumber,soh.PurchaseOrderNumber,j.Name as TerritoryName, soh.ShipMethodID,cast( soh.SubTotal as decimal(35,2))as Subtotal, cast( soh.Freight as decimal(35,2))as Freight, cast(soh.TaxAmt as decimal(35,2))as TaxAmt , soh.TotalDue,year( soh.OrderDate) ||-|| monthname( soh.OrderDate) ||-|| day( soh.OrderDate) ||-||dayname( soh.OrderDate)||,|| quarter( soh.OrderDate) as OrderDateFROM Sales.Customer cinner joinSales.SalesOrderHeader sohon c.CustomerID = soh.CustomerIDinner joinSales.SalesOrderDetail sodon soh.SalesOrderID = sod.SalesOrderIDinner join Sales.SalesTerritory jonsoh.TerritoryID = j.TerritoryIDSELECT CustomerID AS CUSTOMER_ID, CAST (AVG(TotalDue)AS DECIMAL (35,2)) AS AVG_TOTAL_DUE, CAST (SUM(TOTALDUE)AS DECIMAL(35,2)) SUM_TOTAL,CAST (MAX(TotalDue)AS DECIMAL(35,2))AS MAX_TOTAL_DUE, CAST (MIN(TotalDue)AS DECIMAL(35,2))AS MIN_TOTAL_DUE2FROM ORDERSGROUP BY CustomerIDCUSTOMER_ID AVG_TOTAL_DUE SUM_TOTAL MAX_TOTAL_DUE MIN_TOTAL_DUE20818 1259.80 7558.83 3953.99 720.9724921 1254.27 5017.08 1303.87 1105.4812648 2596.35 20770.84 2699.01 2264.2516727 2708.69 5417.37 2708.69 2708.6929012 87.27 174.55 87.27 87.2712655 2814.05 30954.56 3953.99 2673.0620817 2275.34 4550.68 3953.99 596.6924920 1219.70 3659.09 1276.81 1105.4816726 8.04 16.09 8.04 8.0429019 1890.64 5671.91 3953.99 858.9620816 1257.95 7547.72 3953.99 718.7512654 32.54 130.17 40.08 9.9324927 211.35 845.41 211.35 211.3529018 70.69 212.06 70.69 70.6916725 15.45 30.90 15.45 15.4529017 3953.99 3953.99 3953.99 3953.99Results AbridgedSELECT SOH.SalesOrderNumber, CAST (SOH.OrderDate AS DATE) AS OrderDate , CAST (SOH.DueDate AS DATE) AS DueDate, CAST (SOH.ShipDate AS DATE) AS ShipDate, SOD.ProductID,SOH.CUSTOMERID AS CustomerID, cast (SOH.SUBTOTAL as Decimal (35,2))AS SubTotal,cast (SOH.TAXAMT as Decimal (35,2))AS TaxAmt, cast (SOH.FREIGHT as Decimal (35,2))AS Freight, cast (SOH.TOTALDUE as Decimal (35,2))AS TotalDue, PD.Name AS ProductName, ST.NAME as TerritoryName,ST.CountryRegionCode,ST."Group" AS TerritoryGroup, ST.TerritoryIDINTO ORDERS_RECORDFROM Sales.SalesOrderDetail SODINNER JOIN Sales.SalesOrderHeader SOHONSOD.SalesOrderID = SOH.SalesOrderIDINNER JOIN Production.Product PDON SOD.PRODUCTID = PD.PRODUCTIDINNER JOINSALES.SalesTerritory STONSOH.TerritoryID = ST.TerritoryIDORDER BY ST.CountryRegionCodeNote Group is a reserved word and to use that column with name group, a double quotation has to be embraced to allow Sybase SQL Anywhere database to process the query.Select * from ORDERS_RECORDSalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryIDSO43701 2001-07-01 2001-07-13 2001-07-08 773 11003 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 44 Australia AU Pacific 9
  • 16. 15SO43703 2001-07-02 2001-07-14 2001-07-09 749 16624 3578.27 286.26 89.46 3953.99 Road-150 Red, 62 Australia AU Pacific 9SO43704 2001-07-02 2001-07-14 2001-07-09 778 11005 3374.99 270.00 84.37 3729.36 Mountain-100 Black, 48 Australia AU Pacific 9SO43705 2001-07-02 2001-07-14 2001-07-09 771 11011 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 38 Australia AU Pacific 9SO43709 2001-07-03 2001-07-15 2001-07-10 752 16351 3578.27 286.26 89.46 3953.99 Road-150 Red, 52 Australia AU Pacific 9SO43710 2001-07-03 2001-07-15 2001-07-10 753 16517 3578.27 286.26 89.46 3953.99 Road-150 Red, 56 Australia AU Pacific 9SO43715 2001-07-05 2001-07-17 2001-07-12 753 16483 3578.27 286.26 89.46 3953.99 Road-150 Red, 56 Australia AU Pacific 9SO43716 2001-07-05 2001-07-17 2001-07-12 750 16529 3578.27 286.26 89.46 3953.99 Road-150 Red, 44 Australia AU Pacific 9SO43717 2001-07-05 2001-07-17 2001-07-12 767 25249 699.10 55.93 17.48 772.50 Road-650 Black, 62 Australia AU Pacific 9SO43724 2001-07-07 2001-07-19 2001-07-14 750 16520 3578.27 286.26 89.46 3953.99 Road-150 Red, 44 Australia AU Pacific 9SO43727 2001-07-08 2001-07-20 2001-07-15 750 16607 3578.27 286.26 89.46 3953.99 Road-150 Red, 44 Australia AU Pacific 9SO43731 2001-07-09 2001-07-21 2001-07-16 753 16629 3578.27 286.26 89.46 3953.99 Road-150 Red, 56 Australia AU Pacific 9SO43732 2001-07-09 2001-07-21 2001-07-16 777 11025 3374.99 270.00 84.37 3729.36 Mountain-100 Black, 44 Australia AU Pacific 9SO43735 2001-07-10 2001-07-22 2001-07-17 749 16522 3578.27 286.26 89.46 3953.99 Road-150 Red, 62 Australia AU Pacific 9SO43736 2001-07-10 2001-07-22 2001-07-17 773 11002 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 44 Australia AU Pacific 9SO43740 2001-07-11 2001-07-23 2001-07-18 751 16527 3578.27 286.26 89.46 3953.99 Road-150 Red, 48 Australia AU Pacific 9SO43743 2001-07-12 2001-07-24 2001-07-19 774 11007 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 48 Australia AU Pacific 9SO43744 2001-07-12 2001-07-24 2001-07-19 752 16631 3578.27 286.26 89.46 3953.99 Road-150 Red, 52 Australia AU Pacific 9SO43745 2001-07-13 2001-07-25 2001-07-20 750 16514 3578.27 286.26 89.46 3953.99 Road-150 Red, 44 Australia AU Pacific 9SO43746 2001-07-13 2001-07-25 2001-07-20 751 16616 3578.27 286.26 89.46 3953.99 Road-150 Red, 48 Australia AU Pacific 9Results Abridgedselect top(5) * from ORDERS_RECORDSalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryIDSO43701 2001-07-01 2001-07-13 2001-07-08 773 11003 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 44 Australia AU Pacific 9SO43703 2001-07-02 2001-07-14 2001-07-09 749 16624 3578.27 286.26 89.46 3953.99 Road-150 Red, 62 Australia AU Pacific 9SO43704 2001-07-02 2001-07-14 2001-07-09 778 11005 3374.99 270.00 84.37 3729.36 Mountain-100 Black, 48 Australia AU Pacific 9SO43705 2001-07-02 2001-07-14 2001-07-09 771 11011 3399.99 272.00 85.00 3756.99 Mountain-100 Silver, 38 Australia AU Pacific 9SO43709 2001-07-03 2001-07-15 2001-07-10 752 16351 3578.27 286.26 89.46 3953.99 Road-150 Red, 52 Australia AU Pacific 9Results Abridged/*This table would be used to hold data relating to GB customers*/Create table Territory_ReportGB(SalesOrderNumber NVARCHAR(25),ORDERDATE DATE,DUEDATE DATE,SHIPDATE DATE,PRODUCTID INTEGER ,CUSTOMERID INTEGER ,SUBTOTAL DECIMAL (35,2),TAXAMT DECIMAL(35,2),FREIGHT DECIMAL(35,2),TOTALDUE DECIMAL(35,2),PRODUCTNAME NAME,DESCRIPTION NVARCHAR(400),COLOR NVARCHAR(15) ,SIZE NVARCHAR(15) ,SizeUnitMeasureCode NCHAR(3),SubCatgoName NAME,ProductSubcategoryID INTEGER,CategoryName NAME ,ProductCategoryID INTEGER,TerritoryName NAME ,CountryRegionCode NVARCHAR(3),TerritoryGroup NVARCHAR(50),TerritoryID INTEGER,REPORT_ID INTEGER IDENTITY ,REPORT_DATE TIMESTAMP default TIMESTAMP);ALTER TABLE Territory_ReportGBADD CONSTRAINT TERRITRPORT_RPID_PK PRIMARY KEY(REPORT_ID);ALTER TABLE Territory_ReportGBadd AccountNumber varchar(30);/* A stored procedure will call this view to populate the report table for GB customers*/create view SalesReportsASSELECT SOH.SalesOrderNumber, CU.AccountNumber, CAST (SOH.OrderDate AS DATE) AS OrderDate , CAST (SOH.DueDate AS DATE) AS DueDate, CAST (SOH.ShipDate AS DATE) AS ShipDate, PD.ProductID,SOH.CUSTOMERID AS CustomerID, cast (SOH.SUBTOTAL as Decimal (35,2))AS SubTotal,cast (SOH.TAXAMT as Decimal (35,2))AS TaxAmt, cast (SOH.FREIGHT as Decimal (35,2))AS Freight, cast (SOH.TOTALDUE as Decimal (35,2))AS TotalDue,PD.NAME AS PRODUCTNAME, PPD.Description,PD.COLOR,PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgoName,PSC.ProductSubcategoryID,PC.Name AS CategoryName, PC.ProductCategoryID,ST.NAME as TerritoryName,ST.CountryRegionCode ,ST."Group" AS TerritoryGroup,ST.TerritoryIDFROM Sales.SalesOrderDetail SODINNER JOIN Sales.SalesOrderHeader SOHONSOD.SalesOrderID = SOH.SalesOrderIDINNER JOIN Production.Product PDON SOD.PRODUCTID = PD.PRODUCTID
  • 17. 16INNER JOINSALES.SalesTerritory STONSOH.TerritoryID = ST.TerritoryIDINNER JOINProduction.ProductModel PMONPM.ProductModelID = PD.ProductModelIDINNER JOINProduction. ProductModelProductDescriptionCulture PMPDCONPM.ProductModelID = PMPDC.ProductModelIDINNER JOINProduction.ProductDescription PPDONPPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDINNER JOIN SALES.Customer CUON SOH.CustomerID = CU.CustomerIDINNER JOINPRODUCTION.ProductCategory PCONPSC.ProductCategoryID = PC.ProductCategoryID;/* Report audit table that would be used to keep tracks of the records inserted, deleted and updated to the territory report GB table*/CREATE TABLE REPORT_ADUIT(SalesOrderNumber NVARCHAR(25),ORDERDATE DATE,DUEDATE DATE,SHIPDATE DATE,PRODUCTID INTEGER ,CUSTOMERID INTEGER ,SUBTOTAL DECIMAL (35,2),TAXAMT DECIMAL(35,2),FREIGHT DECIMAL(35,2),TOTALDUE DECIMAL(35,2),PRODUCTNAME NAME,DESCRIPTION NVARCHAR(400),COLOR NVARCHAR(15) ,SIZE NVARCHAR(15) ,SizeUnitMeasureCode NCHAR(3),SubCatgoName NAME,ProductSubcategoryID INTEGER,CategoryName NAME ,ProductCategoryID INTEGER,TerritoryName NAME ,CountryRegionCode NVARCHAR(3),TerritoryGroup NVARCHAR(50),TerritoryID INTEGER,REPORT_ID INTEGER,ADUIT_ID INTEGER IDENTITY ,ADUIT_DATE TIMESTAMP DEFAULT TIMESTAMP,REPORT_DATE TIMESTAMP);ALTER TABLE REPORT_ADUITADD CONSTRAINT REPORTAD_ADID_PK PRIMARY KEY(ADUIT_ID);ALTER TABLE REPORT_ADUITadd AccountNumber varchar(30);/* This table would hold data associated with customers from different regions */Create table Territory_ReportS(SalesOrderNumber NVARCHAR(25),ORDERDATE DATE,DUEDATE DATE,SHIPDATE DATE,PRODUCTID INTEGER ,CUSTOMERID INTEGER ,SUBTOTAL DECIMAL (35,2),TAXAMT DECIMAL(35,2),FREIGHT DECIMAL(35,2),
  • 18. 17TOTALDUE DECIMAL(35,2),PRODUCTNAME NAME,DESCRIPTION NVARCHAR(400),COLOR NVARCHAR(15) ,SIZE NVARCHAR(15) ,SizeUnitMeasureCode NCHAR(3),SubCatgoName NAME,ProductSubcategoryID INTEGER,CategoryName NAME ,ProductCategoryID INTEGER,TerritoryName NAME ,CountryRegionCode NVARCHAR(3),TerritoryGroup NVARCHAR(50),TerritoryID INTEGER,REPORT_ID INTEGER IDENTITY ,REPORT_DATE TIMESTAMP default TIMESTAMP ,AccountNumber varchar(30),CONSTRAINT REPORTID_PK PRIMARY KEY(REPORT_ID));INSERT INTO "DBA"."Territory_ReportGB"(SalesOrderNumber,AccountNumber, ORDERDATE,DUEDATE,SHIPDATE, PRODUCTID,CUSTOMERID ,SUBTOTAL,TAXAMT,FREIGHT, TOTALDUE,PRODUCTNAME,"DESCRIPTION",COLOR,"SIZE",SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID)SELECT SalesOrderNumber, AccountNumber, OrderDate , DueDate, ShipDate, ProductID,CustomerID, SubTotal,TaxAmt, Freight, TotalDue,PRODUCTNAME, "Description","COLOR" ,"Size", SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID,TerritoryName,CountryRegionCode , TerritoryGroup, TerritoryIDFROM SalesReportsWHERE CountryRegionCode =GBselect * from REPORT_ADUIT/*The null column has been removed to allow the report fit to the document*/SalesOrderNumberORDERDATEDUEDATESHIPDATEPRODUCTIDCUSTOMERIDSUBTOTALTAXAMTFREIGHTTOTALDUEPRODUCTNAMEDESCRIPTION COLORSubCatgoNameProductSubcategoryIDCategoryNameProductCategoryIDTerritoryNameCountryRegionCodeTerritoryGroupTerritoryIDREPORT_IDADUIT_IDADUIT_DATEREPORT_DATESO57240 11/1/200311/13/200311/8/2003712 11238 562.96 45.04 14.07 622.07 AWC LogoCap经典式样,带有翻边;均码。Multi Caps 19 Clothing 3 UnitedKingdomGB Europe 10 8 3 5/6/20130:025/6/20130:02SO57240 11/1/200311/13/200311/8/2003712 11238 562.96 45.04 14.07 622.07 AWC LogoCapMulti Caps 19 Clothing 3 UnitedKingdomGB Europe 10 9 4 5/6/20130:025/6/20130:02Results Abridged/* A trigger will populate the territory reports for GB customer*/INSERT INTO Territory_ReportS(SalesOrderNumber,AccountNumber, ORDERDATE,DUEDATE,SHIPDATE, PRODUCTID,CUSTOMERID ,SUBTOTAL,TAXAMT,FREIGHT, TOTALDUE,PRODUCTNAME,"DESCRIPTION",COLOR,"SIZE",SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID)SELECT SalesOrderNumber, AccountNumber, OrderDate , DueDate, ShipDate, ProductID,CustomerID, SubTotal,TaxAmt, Freight, TotalDue,PRODUCTNAME, "Description","COLOR" ,"Size", SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID,TerritoryName,CountryRegionCode , TerritoryGroup, TerritoryIDFROM SalesReportsWHERE CountryRegionCode =GBINSERT INTO Territory_ReportS(SalesOrderNumber,AccountNumber, ORDERDATE,DUEDATE,SHIPDATE, PRODUCTID,CUSTOMERID ,SUBTOTAL,TAXAMT,FREIGHT, TOTALDUE,PRODUCTNAME,"DESCRIPTION",COLOR,"SIZE",SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID)SELECT SalesOrderNumber, AccountNumber, OrderDate , DueDate, ShipDate, ProductID,
  • 19. 18CustomerID, SubTotal,TaxAmt, Freight, TotalDue,PRODUCTNAME, "Description","COLOR" ,"Size", SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID,TerritoryName,CountryRegionCode , TerritoryGroup, TerritoryIDFROM SalesReportsWHERE CountryRegionCode =USselect TOP(2) * fromTerritory_ReportGB;SalesOrderNumberORDERDATEDUEDATESHIPDATEPRODUCTIDCUSTOMERIDSUBTOTALTAXAMTFREIGHTTOTALDUEPRODUCTNAMEDESCRIPTION COLORSIZESizeUnitMeasureCodeSubCatgoNameProductSubcategoryIDCategoryNameProductCategoryIDTerritoryNameCountryRegionCodeTerritoryGroupTerritoryIDREPORT_IDREPORT_DATEAccountNumberSO51411 2003-07-152003-07-272003-07-22712 11239 2353.95 188.3258.85 2601.11 AWC LogoCap经典式样,带有翻边;均码。Multi Caps 19 Clothing 3 UnitedKingdomGB Europe 10 88 2013-05-0916:55:53.763AW00011239SO51411 2003-07-152003-07-272003-07-22712 11239 2353.95 188.3258.85 2601.11 AWC LogoCap‫עם‬ ‫מסורתי‬ ‫סגנון‬‫גודל‬ ;‫מתרוממת‬ ‫מצחייה‬.‫לכולם‬ ‫מתאים‬ ‫אחד‬Multi Caps 19 Clothing 3 UnitedKingdomGB Europe 10 89 2013-05-0916:55:53.764AW00011239select * from Territory_ReportGBWHERE CountryRegionCode = USSalesOrderNumber ORDERDATE DUEDATE SHIPDATE PRODUCTID CUSTOMERID SUBTOTAL TAXAMT FREIGHT TOTALDUE PRODUCTNAME DESCRIPTIONCOLOR SIZE SizeUnitMeasureCode SubCatgoName ProductSubcategoryID CategoryName ProductCategoryID TerritoryName CountryRegionCode TerritoryGroup TerritoryID REPORT_IDREPORT_DATE AccountNumber------------------------- ---------- ---------- ---------- ----------- ----------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- --------------- ------------------- -------------------------------------------------- -------------------- -------------------------------------------------- ----------------- -------------------------------------------------- ----------------- -------------------------------------------------- ----------- ----------- ----------------------- ------------------------------(0 rows)Execution time: 0.208 secondsselect TOP(5) * fromTerritory_ReportSWHERE CountryRegionCode =GB’SalesOrderNumberORDERDATEDUEDATESHIPDATEPRODUCTIDCUSTOMERIDSUBTOTALTAXAMTFREIGHTTOTALDUEPRODUCTNAMEDESCRIPTION COLORSIZESizeUnitMeasureCodeSubCatgoNameProductSubcategoryIDCategoryNameProductCategoryIDTerritoryNameCountryRegionCodeTerritoryGroupTerritoryIDREPORT_IDREPORT_DATEAccountNumberSO57240 2003-11-012003-11-132003-11-08712 11238 562.96 45.04 14.07 622.07 AWC LogoCap经典式样,带有翻边;均码。MultiCaps 19 Clothing 3 UnitedKingdomGB Europe 10 4 2013-05-0916:55:53.552AW00011238SO57240 2003-11-012003-11-132003-11-08712 11238 562.96 45.04 14.07 622.07 AWC LogoCap‫מצחייה‬ ‫עם‬ ‫מסורתי‬ ‫סגנון‬‫מתאים‬ ‫אחד‬ ‫גודל‬ ;‫מתרוממת‬.‫לכולם‬MultiCaps 19 Clothing 3 UnitedKingdomGB Europe 10 5 2013-05-0916:55:53.656AW00011238SO57240 2003-11-012003-11-132003-11-08712 11238 562.96 45.04 14.07 622.07 AWC LogoCapMultiCaps 19 Clothing 3 UnitedKingdomGB Europe 10 6 2013-05-0916:55:53.657AW00011238SO57240 2003-11-012003-11-132003-11-08712 11238 562.96 45.04 14.07 622.07 AWC LogoCapStyle classique avecune visière relevable ;taille unique.MultiCaps 19 Clothing 3 UnitedKingdomGB Europe 10 7 2013-05-0916:55:53.660AW00011238SO57240 2003-11-012003-11-132003-11-08712 11238 562.96 45.04 14.07 622.07 AWC LogoCap‫رو‬ ‫ٍذي‬ ‫ه‬ ‫ق‬ ‫ت‬ ‫مط‬ ‫و‬ ‫ح‬ ‫حاف‬،‫هى‬ ‫ألع‬ ‫الب‬‫ق‬ ‫الو‬ ‫ن‬ ‫هح‬ ‫ات‬ ‫ق‬‫م‬ ‫الئ‬ ٌ ‫واحذ‬ ‫حجم‬ ‫ت‬.‫ٍع‬ ‫جم‬ ‫ان‬MultiCaps 19 Clothing 3 UnitedKingdomGB Europe 10 8 2013-05-0916:55:53.661AW00011238select TOP(5) * fromTerritory_ReportSWHERE CountryRegionCode =USalesOrderNumberORDERDATEDUEDATESHIPDATEPRODUCTIDCUSTOMERIDSUBTOTALTAXAMTFREIGHTTOTALDUEPRODUCTNAMEDESCRIPTION COLORSIZESizeUnitMeasureCodeSubCatgoNameProductSubcategoryIDCategoryNameProductCategoryIDTerritoryNameCountryRegionCodeTerritoryGroupTerritoryIDREPORT_IDREPORT_DATEAccountNumberSO43670 2001-07-012001-07-132001-07-08773 29566 7344.50587.56183.618115.68Mountain-100Silver, 44 HLSilver44 CM Mountain Bikes1 Bikes 1 Central US NorthAmerica3 62796 2013-05-0917:06:14.134AW00029566SO43670 2001-07-012001-07-132001-07-08773 29566 7344.50587.56183.618115.68Mountain-100Silver, 44VTT de compétition haut de gamme. Plusieursoptions damélioration des performances : cadre HL,suspension avant particulièrement souple et tractionadaptée à tous les terrains.Silver44 CM Mountain Bikes1 Bikes 1 Central US NorthAmerica3 62797 2013-05-0917:06:14.134AW00029566SO43670 2001-07-012001-07-132001-07-08773 29566 7344.50587.56183.618115.68Mountain-100Silver, 44‫هى‬ ‫أع‬ ‫مه‬ ‫ثال‬ ‫ج‬ ‫ان‬ ً ‫ف‬ ‫ٍادج‬ ‫ق‬ ‫ه‬ ‫ن‬ ‫صح‬ ‫ص‬ ‫مخ‬ ‫اخ‬ ‫ثاق‬ ‫س‬ ‫دراجح‬emarF LH ‫كم‬ ٍ ‫ه‬ ‫األداء‬ ‫ٍه‬ ‫س‬ ‫ح‬ ‫ت‬ ‫ٍاراخ‬ ‫خ‬ ‫ضمه‬ ‫ت‬ ‫ت‬ .‫طراز‬‫وج‬ ‫وق‬ ،‫قح‬ ‫فائ‬ ‫ان‬ ‫سح‬ ‫ال‬‫س‬ ‫ان‬ ‫ري‬ ً‫ام‬‫األم‬ ‫ٍق‬ ‫ه‬ ‫ع‬‫ت‬ ‫وان‬ ،ً‫ذاع‬ ‫اإلت‬.ً‫ض‬ ‫األرا‬ ‫واع‬ ‫أو‬ ‫ٍع‬ ‫جم‬ ‫ن‬ ‫ثح‬ ‫س‬ ‫ىا‬ ‫م‬ ‫ان‬ ‫جر‬ ‫ان‬Silver44 CM Mountain Bikes1 Bikes 1 Central US NorthAmerica3 62798 2013-05-0917:06:14.134AW00029566
  • 20. 19SO43670 2001-07-012001-07-132001-07-08773 29566 7344.50587.56183.618115.68Mountain-100Silver, 44Top-of-the-line competition mountain bike.Performance-enhancing options include theinnovative HL Frame, super-smooth front suspension,and traction for all terrain.Silver44 CM Mountain Bikes1 Bikes 1 Central US NorthAmerica3 62799 2013-05-0917:06:14.134AW00029566SO43670 2001-07-012001-07-132001-07-08776 29566 7344.50587.56183.618115.68Mountain-100Black, 42高档竞赛山地车。性能得到进一步增强,包括创新的 HL车架、极其平稳的前悬架以及适用于所有地形的出色牵引力。Black42 CM Mountain Bikes1CREATE or replace VIEW PRODUCTHASSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PPD.Description,PSC.Name AS SubCatgo_Name, PSC.ProductSubcategoryID AS SubCatgo_ID,PPI.Quantity,PPI.Shelf, PPI.LocationID, CAST(PPI.ModifiedDate AS DATE)AS ModifiedDate_SubCatgo,PPI.Bin ,CUL.Name AS Culture_Name,PCI.Name AS Catego_Name, PCI.ProductCategoryID , cast( PCI.ModifiedDate as date)AS ModifiedDate_CategoFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDINNER JOINPRODUCTION.ProductInventory PPIONPD.ProductID = PPI.ProductIDINNER JOINPRODUCTION.ProductCategory PCIONPSC.ProductCategoryID = PCI.ProductCategoryIDCREATE TABLE PRODHISTORY(Product_ID INTEGER,Product_Name NAME,Product_Color Nvarchar(15),Product_Size Nvarchar(5),SizeUnitMeasureCode nchar(3),Product_Description nvarchar(400),SubCatgo_Name name,Quantity char(8),Shelf nvarchar(10),LocationID char(8),ModifiedDate_SubCatgo Timestamp,P_Bin CHAR(8),Culture_Name NAME,History_Date Timestamp Default Timestamp ,History_ID INTEGER IDENTITY ,Category_Name Name,ModifiedDate_Catgo Timestamp,SubCatgo_ID integer,Prod_CatgoID INTEGER,constraint PHISTORY_PRODID2_PK PRIMARY KEY (HISTORY_ID))/*This stored procedure will populate the above table*/CREATE OR REPLACE PROCEDURE ProdHistory(in @ProductID INTEGER)BEGINIF @ProductID IS NOT NULLTHENINSERT INTO PRODHISTORY (Product_ID, Product_Name ,Product_Color , Product_Size , SizeUnitMeasureCode , Product_Description,SubCatgo_Name, Quantity ,Shelf ,LocationID , ModifiedDate_SubCatgo, P_Bin , Culture_Name, Category_Name,
  • 21. 20ModifiedDate_Catgo, SubCatgo_ID,Prod_CatgoID)SELECT ProductID, "Name" ,Color , "Size" , SizeUnitMeasureCode , "Description",SubCatgo_Name,Quantity, Shelf, LocationID, ModifiedDate_SubCatgo,Bin ,Culture_Name,Catego_Name, ModifiedDate_Catego,SubCatgo_ID,ProductCategoryIDFROM PRODUCTHWHERE ProductID = @ProductID ;END IF ;EndSELECT * FROM PRODHISTORYProduct_IDProduct_NameProduct_ColorProduct_SizeSizeUnitMeasureCodeProduct_Description SubCatgo_NameQuantityShelfLocationIDModifiedDate_SubCatgoP_BinCulture_NameHistory_DateHistory_IDCategory_NameModifiedDate_CatgoSubCatgo_IDProd_CatgoID865 Classic Vest,MBlue M Light-weight, wind-resistant, packs to fit intoa pocket.Vests 216 N/A 7 2003-06-0100:00:00.0000 English 2013-05-0921:06:18.6541 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬ ،‫ح‬ ٌ‫هر‬ ‫ن‬.‫ٍة‬ ‫ج‬ ‫ان‬Vests 216 N/A 7 2003-06-0100:00:00.0000 Arabic 2013-05-0921:06:18.6552 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M Sacs légers et résistants auvent ; tiennent dans lapoche.Vests 216 N/A 7 2003-06-0100:00:00.0000 French 2013-05-0921:06:18.6553 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M Vests 216 N/A 7 2003-06-0100:00:00.0000 Thai 2013-05-0921:06:18.6554 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M ‫-קל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬.‫לכיס‬ ‫המתאים‬ ‫לגודל‬Vests 216 N/A 7 2003-06-0100:00:00.0000 Hebrew 2013-05-0921:06:18.6555 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M 轻型抗风,可折叠放入口袋。Vests 216 N/A 7 2003-06-0100:00:00.0000 Chinese 2013-05-0921:06:18.6566 Clothing 1998-06-0100:00:00.00025 3TriggersCREATE OR REPLACE TRIGGER T_ReportsBEFORE INSERT ON Territory_ReportSREFERENCING NEW AS NFOR EACH ROWBEGINSET self_recursion OFF;CASE WHEN N.CountryRegionCode =GBTHENINSERT INTO Territory_ReportGB(SalesOrderNumber,AccountNumber, ORDERDATE,DUEDATE,SHIPDATE, PRODUCTID,CUSTOMERID ,SUBTOTAL,TAXAMT,FREIGHT, TOTALDUE,PRODUCTNAME,DESCRIPTION,COLOR,SIZE,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID,REPORT_ID,REPORT_DATE)VALUES(N.SalesOrderNumber,N.AccountNumber,N.ORDERDATE,N.DUEDATE,N.SHIPDATE, N.PRODUCTID,N.CUSTOMERID ,N.SUBTOTAL,N.TAXAMT,N.FREIGHT, N.TOTALDUE,N.PRODUCTNAME,N.DESCRIPTION,N.COLOR,N.SIZE,N.SizeUnitMeasureCode,N.SubCatgoName,N.ProductSubcategoryID, N.CategoryName, N.ProductCategoryID, N.TerritoryName,N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID,N.REPORT_DATE);END CASEENDCREATE OR REPLACE TRIGGER TERRITORYRPT_GBAFTER INSERT ON Territory_ReportGBREFERENCING NEW AS NFOR EACH ROWBEGINSET self_recursion OFF;INSERT INTO REPORT_ADUIT(SalesOrderNumber,AccountNumber, ORDERDATE,DUEDATE,SHIPDATE, PRODUCTID,CUSTOMERID ,SUBTOTAL,TAXAMT,FREIGHT, TOTALDUE,PRODUCTNAME,DESCRIPTION,COLOR,SIZE,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID,REPORT_ID,REPORT_DATE)VALUES(N.SalesOrderNumber,N.AccountNumber,N.ORDERDATE,N.DUEDATE,N.SHIPDATE, N.PRODUCTID,N.CUSTOMERID ,N.SUBTOTAL,N.TAXAMT,N.FREIGHT, N.TOTALDUE,N.PRODUCTNAME,N.DESCRIPTION,N.COLOR,N.SIZE,N.SizeUnitMeasureCode,N.SubCatgoName,
  • 22. 21N.ProductSubcategoryID, N.CategoryName, N.ProductCategoryID, N.TerritoryName,N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID,N.REPORT_DATE);ENDXMLSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PD.ProductID = 713FOR XML AUTOforxml(2,PD,forxml_sep(),ProductID,xmltab."1",NAME,xmltab."2",COLOR,xmltab."3",Size,xmltab."4",SizeUnitMeasureCode,xmltab."5",PSC,forxml_sep(),SubCatgo_Name,xmltab."6")----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<PD ProductID="713" NAME="Long-Sleeve Logo Jersey, S" COLOR="Multi" Size="S"><PSC SubCatgo_Name="Jerseys"/></PD>(1 rows)Execution time: 0.125 secondsSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PD.ProductID = 713FOR XML RAWforxml(1,ProductID,xmltab."1",NAME,xmltab."2",COLOR,xmltab."3",Size,xmltab."4",SizeUnitMeasureCode,xmltab."5",SubCatgo_Name,xmltab."6")----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<row ProductID="713" NAME="Long-Sleeve Logo Jersey, S" COLOR="Multi" Size="S" SubCatgo_Name="Jerseys"/>(1 rows)Execution time: 0.044 secondsSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSC
  • 23. 22ONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PD.ProductID = 713FOR XML RAW, ELEMENTSforxml(33,ProductID,xmltab."1",NAME,xmltab."2",COLOR,xmltab."3",Size,xmltab."4",SizeUnitMeasureCode,xmltab."5",SubCatgo_Name,xmltab."6")----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<row><ProductID>713</ProductID><NAME>Long-Sleeve Logo Jersey, S</NAME><COLOR>Multi</COLOR><Size>S</Size><SubCatgo_Name>Jerseys</SubCatgo_Name></row>(1 rows)Execution time: 0.065 secondsSELECT ProductID, xmlelement(NAME DESCRIPTION,xmlforest(PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name) ) AS Prod_InfoFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PD.ProductID = 713FOR XML RAW, ELEMENTSforxml(1,ProductID,xmltab."1",Prod_Info,xmltab."2")----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<row ProductID="713" Prod_Info="<DESCRIPTION><ProductID>713</ProductID><NAME>Long-Sleeve Logo Jersey,S</NAME><COLOR>Multi</COLOR><Size>S</Size><SubCatgo_Name>Jerseys</SubCatgo_Name></DES(1 rows)Execution time: 0.029 secondsSELECT ProductID, xmlelement(NAME DESCRIPTION,xmlforest(PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name) ) AS Prod_InfoFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PD.ProductID = 713ProductID Prod_Info----------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------713 <DESCRIPTION><ProductID>713</ProductID><NAME>Long-Sleeve Logo Jersey, S</NAME><COLOR>Multi</COLOR><Size>S</Size><SubCatgo_Name>Jerseys</SubCatgo_Name></DESCRIPTION>(1 rows)Execution time: 0.036 secondsCursorsCREATE VIEW EMOINFOASSELECT HRE.BusinessEntityID,PER.FirstName, PER.MiddleName , PER.LastName,HRE.BirthDate, HRE.Gender, HRE.MaritalStatus, HRE.NationalIDNumber,HRE.SickLeaveHours, HRE.VacationHours,DATEDIFF(YY, BirthDate , CURRENT_TIMESTAMP) AS AGEFROM HumanResources.Employee HRE
  • 24. 23INNER JOIN PERSON.Person PERONHRE.BusinessEntityID = PER.BusinessEntityIDBEGINDECLARE @BusinessEntityID INTEGER;DECLARE @EMP_NMAME VARCHAR(55);DECLARE @BDATE DATE;DECLARE @GENDER CHAR(2);DECLARE @MSTATUS CHAR(8);DECLARE @NATIONALID INTEGER;DECLARE @SICKH INTEGER;DECLARE @VHOURS INTEGER;DECLARE @EMPAGE INTEGER;DECLARE @EMPRED CURSOR FORSELECT BusinessEntityID,FirstName||,|| MiddleName||,||LastName as Emp_Name,BirthDate, Gender, MaritalStatus, NationalIDNumber,SickLeaveHours, VacationHours,AGEFROM EMOINFOwhere BusinessEntityID = 19;OPEN @EMPRED;fetch next @EMPREDinto @BusinessEntityID, @EMP_NMAME, @BDATE, @GENDER,@MSTATUS, @NATIONALID, @SICKH,@VHOURS, @EMPAGE;select @BusinessEntityID , @EMP_NMAME , @BDATE , @GENDER ,@MSTATUS , @NATIONALID , @SICKH ,@VHOURS,@EMPAGE ;CLOSE @EMPRED;END;@BusinessEntityID @EMP_NMAME @BDATE @GENDER @MSTATUS @NATIONALID @SICKH @VHOURS @EMPAGE----------------- ------------------------------------------------------- ---------- ------- -------- ----------- ----------- ----------- -----------19 Mary,A,Dempsey 1968-03-01 F S 52541318 41 43 45Execution time: 0.047 seconds
  • 25. 24DBACopying data from Sybase SQL AnyWhere AdventureWorks Database to Sybase SQL AnyWhere Rock Database using Sybase Central
  • 26. 25
  • 27. 26SELECT * FROM "SUNNY"."PRODHISTORY"Product_IDProduct_NameProduct_ColorProduct_SizeSizeUnitMeasureCodeProduct_Description SubCatgo_NameQuantityShelfLocationIDModifiedDate_SubCatgoP_BinCulture_NameHistory_DateHistory_IDCategory_NameModifiedDate_CatgoSubCatgo_IDProd_CatgoID865 Classic Vest,MBlue M Light-weight, wind-resistant, packs tofit into a pocket.Vests 216 N/A 7 2003-06-0100:00:00.0000 English 2013-05-0921:06:18.6541 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M ،‫ح‬ ٌ‫هر‬ ‫ن‬ ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬.‫ٍة‬ ‫ج‬ ‫ان‬ ‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬Vests 216 N/A 7 2003-06-0100:00:00.0000 Arabic 2013-05-0921:06:18.6552 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M Sacs légers et résistants au vent ;tiennent dans la poche.Vests 216 N/A 7 2003-06-0100:00:00.0000 French 2013-05-0921:06:18.6553 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M Vests 216 N/A 7 2003-06-0100:00:00.0000 Thai 2013-05-0921:06:18.6554 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M ‫-קל‬ ‫המתאים‬ ‫לגודל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬.‫לכיס‬Vests 216 N/A 7 2003-06-0100:00:00.0000 Hebrew 2013-05-0921:06:18.6555 Clothing 1998-06-0100:00:00.00025 3865 Classic Vest,MBlue M 轻型抗风,可折叠放入口袋。 Vests 216 N/A 7 2003-06-0100:00:00.0000 Chinese 2013-05-0921:06:18.6566 Clothing 1998-06-0100:00:00.00025 3select * from sysprocedure where PROC_NAME =ProdHistory ORPROC_NAME =PRODUCTSORPROC_NAME =PRODUCTS2ORPROC_NAME =SALES_TERRITORY_GBORPROC_NAME = SalesTerritory_Reportproc_idcreatorobject_idproc_name proc_defn remarksreplicatesrvidsource avg_num_rowsavg_coststats353 1 4728 ProdHistory create procedure DBA.ProdHistory(in @ProductID integer )beginif @ProductID is not null theninsert into PRODHISTORY( Product_ID,Product_Name,Product_Color,Product_Size,SizeUnitMeasureCode,Product_Description,SubCatgo_Name,Quantity,Shelf,LocationID,ModifiedDate_SubCatgo,P_Bin,Culture_Name,Category_Name,ModifiedDate_Catgo,SubCatgo_ID,Prod_CatgoID )select ProductID,Name,Color,Size,SizeUnitMeasureCode,Description,SubCatgo_Name,Quantity,Shelf,LocationID,ModifiedDate_SubCatgo,Bin,Culture_Name,Catego_Name,ModifiedDate_Catego,SubCatgo_ID,ProductCategoryIDfrom PRODUCTHwhere ProductID = @ProductIDend ifendN create PROCEDURE DBA."ProdHistory"(in @ProductID INTEGER)BEGINIF @ProductID IS NOT NULLTHENINSERT INTO PRODHISTORY (Product_ID, Product_Name ,Product_Color ,Product_Size , SizeUnitMeasureCode , Product_Description,SubCatgo_Name, Quantity ,Shelf ,LocationID , ModifiedDate_SubCatgo, P_Bin ,Culture_Name, Category_Name,ModifiedDate_Catgo, SubCatgo_ID,Prod_CatgoID)SELECT ProductID, "Name" ,Color , "Size" , SizeUnitMeasureCode , "Description",SubCatgo_Name,Quantity, Shelf, LocationID, ModifiedDate_SubCatgo,Bin ,Culture_Name,Catego_Name, ModifiedDate_Catego,SubCatgo_ID,ProductCategoryIDFROM PRODUCTHWHERE ProductID = @ProductID ;END IF ;EndBinaryData347 1 4384 PRODUCTS create procedure DBA.PRODUCTSasselect PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode,PPD.Description,SubCatgo_Name=PSC.Namefrom Production.ProductDescription as PPDjoin Production.ProductModelProductDescriptionCulture as PMPDCon PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDjoin Production.ProductModel as PMon PMPDC.ProductModelID = PM.ProductModelIDjoin PRODUCTION.Product as PDon PD.ProductModelID = PM.ProductModelIDjoin PRODUCTION.Culture as CULon PMPDC.CultureID = CUL.CultureIDjoin PRODUCTION.ProductSubcategory as PSCon PSC.ProductSubcategoryID = PD.ProductSubcategoryIDwhere CUL.NAME = ENGLISHN create PROCEDURE PRODUCTS()ASSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PPD.Description,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDBinaryData
  • 28. 27WHERE CUL.NAME = ENGLISH348 1 4385 PRODUCTS2 create procedure DBA.PRODUCTS2(@sub_catgo_name char(35) )asselect PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode,PPD.Description,SubCatgo_Name=PSC.Namefrom Production.ProductDescription as PPDjoin Production.ProductModelProductDescriptionCulture as PMPDCon PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDjoin Production.ProductModel as PMon PMPDC.ProductModelID = PM.ProductModelIDjoin PRODUCTION.Product as PDon PD.ProductModelID = PM.ProductModelIDjoin PRODUCTION.Culture as CULon PMPDC.CultureID = CUL.CultureIDjoin PRODUCTION.ProductSubcategory as PSCon PSC.ProductSubcategoryID = PD.ProductSubcategoryIDwhere CUL.NAME = ENGLISHand PSC.NAME = @sub_catgo_nameN create PROCEDURE PRODUCTS2(@sub_catgo_name char(35))ASSELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PPD.Description,PSC.Name AS SubCatgo_NameFROM Production.ProductDescription PPDInner join Production. ProductModelProductDescriptionCulture PMPDCON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONIDInner JoinProduction.ProductModel PMONPMPDC.ProductModelID = PM.ProductModelIDINNER JOINPRODUCTION.Product PDONPD.ProductModelID = PM.ProductModelIDINNER JOIN PRODUCTION.Culture CULONPMPDC.CultureID = CUL.CultureIDINNER JOINPRODUCTION.ProductSubcategory PSCONPSC.ProductSubcategoryID = PD.ProductSubcategoryIDWHERE CUL.NAME = ENGLISHAND PSC.NAME = @sub_catgo_nameBinaryData352 1 4659 SALES_TERRITORY_GBcreate procedure DBA.SALES_TERRITORY_GB(in @COUNTRYCODE char(8),out SalesOrderNumber nvarchar(25),out AccountNumber varchar(10),out OrderDate date,out DueDate date,out ShipDate date,out ProductID integer,out CustomerID integer,out SubTotal decimal(35,2),out TaxAmt decimal(35,2),out Freight decimal(35,2),out TotalDue decimal(32,2),out PRODUCTNAME NAME,out Description nvarchar(400),out COLOR nvarchar(15),out Size nvarchar(5),out SizeUnitMeasureCode nvarchar(3),out SubCatgoName NAME,out ProductSubcategoryID integer,out CategoryName NAME,out ProductCategoryID integer,out TerritoryName NAME,out CountryRegionCode nvarchar(3),out TerritoryGroup nvarchar(50),out TerritoryID integer )--on exception resume--begincase when @COUNTRYCODE = GB thenselect SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,CustomerID,SubTotal,TaxAmt,Freight,TotalDue,PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryIDfrom SalesReportswhere CountryRegionCode = @COUNTRYCODEend caseendN create PROCEDURE SALES_TERRITORY_GB(in @COUNTRYCODE char(8),OUT SalesOrderNumber NVARCHAR(25),OUT AccountNumber VARCHAR (10),OUT OrderDate DATE ,OUT DueDate DATE,OUT ShipDate DATE,OUT ProductID INTEGER,OUT CustomerID INTEGER,OUT SubTotal DECIMAL(35,2),OUT TaxAmt DECIMAL (35,2),OUT Freight DECIMAL(35,2),OUT TotalDue DECIMAL(32,2),OUT PRODUCTNAME NAME,OUT "Description" NVARCHAR(400),OUT COLOR NVARCHAR (15),OUT "Size" NVARCHAR(5),OUT SizeUnitMeasureCode NVARCHAR (3),OUT SubCatgoName NAME,OUT ProductSubcategoryID INTEGER,OUT CategoryName NAME,OUT ProductCategoryID INTEGER ,OUT TerritoryName NAME,OUT CountryRegionCode NVARCHAR (3),OUT TerritoryGroup NVARCHAR (50),OUT TerritoryID INTEGER )--on exception resume--beginCASE WHEN @COUNTRYCODE = GBTHENselect SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,CustomerID,SubTotal,TaxAmt,Freight,TotalDue,PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryIDfrom SalesReportswhere CountryRegionCode = @COUNTRYCODEEND CASE;endBinaryData346 1 4383 SalesTerritory_Reportcreate procedure DBA.SalesTerritory_Report(@Region_Code char(8) )asselectSOH.SalesOrderNumber,OrderDate=convert(date,SOH.OrderDate),DueDate=convert(date,SOH.DueDate),ShipDate=convert(date,SOH.ShipDate),SOD.ProductID,CustomerID=SOH.CUSTOMERID,SubTotal=convert(decimal(35,2),SOH.SUBTOTAL),TaxAmt=convert(decimal(35,2),SOH.TAXAMT),Freight=convert(decimal(35,2),SOH.FREIGHT),TotalDue=convert(decimal(35,2),SOH.TOTALDUE),ProductName=PD.Name,TerritoryName=ST.NAME,ST.CountryRegionCode,TerritoryGroup=ST."Group",ST.TerritoryIDfrom Sales.SalesOrderDetail as SODjoin Sales.SalesOrderHeader as SOHon SOD.SalesOrderID = SOH.SalesOrderIDjoin Production.Product as PDon SOD.PRODUCTID = PD.PRODUCTIDjoin SALES.SalesTerritory as STon SOH.TerritoryID = ST.TerritoryIDwhere CountryRegionCode = @Region_Codeorder by PD.NAME ascN create PROCEDURE SalesTerritory_Report(@Region_Code Char(8))ASSELECT SOH.SalesOrderNumber, CAST (SOH.OrderDate AS DATE) AS OrderDate ,CAST (SOH.DueDate AS DATE) AS DueDate, CAST (SOH.ShipDate AS DATE) ASShipDate, SOD.ProductID,SOH.CUSTOMERID AS CustomerID, cast (SOH.SUBTOTAL as Decimal (35,2))ASSubTotal,cast (SOH.TAXAMT as Decimal (35,2))AS TaxAmt, cast (SOH.FREIGHT as Decimal(35,2))AS Freight, cast (SOH.TOTALDUE as Decimal (35,2))AS TotalDue, PD.Name ASProductName, ST.NAME as TerritoryName,ST.CountryRegionCode,ST."Group" AS TerritoryGroup, ST.TerritoryIDFROM Sales.SalesOrderDetail SODINNER JOIN Sales.SalesOrderHeader SOHONSOD.SalesOrderID = SOH.SalesOrderIDINNER JOIN Production.Product PDON SOD.PRODUCTID = PD.PRODUCTIDINNER JOINSALES.SalesTerritory STONSOH.TerritoryID = ST.TerritoryIDwhere CountryRegionCode = @Region_CodeORDER BY PD.NAMEBinaryData
  • 29. 28select * from sysTRIGGERSWHERETRIGNAME = TERRITORYRPT_GB OR TRIGNAME =T_Reportsowner trigname tname event trigtime trigdefnDBA T_Reports Territory_ReportS INSERT BEFORE create trigger T_Reports before insert onDBA.Territory_ReportSreferencing new as Nfor each rowbeginset self_recursion off;case when N.CountryRegionCode = GB theninsert into Territory_ReportGB( SalesOrderNumber,AccountNumber,ORDERDATE,DUEDATE,SHIPDATE,PRODUCTID,CUSTOMERID,SUBTOTAL,TAXAMT,FREIGHT,TOTALDUE,PRODUCTNAME,DESCRIPTION,COLOR,SIZE,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID,REPORT_ID,REPORT_DATE ) values( N.SalesOrderNumber,N.AccountNumber,N.ORDERDATE,N.DUEDATE,N.SHIPDATE,N.PRODUCTID,N.CUSTOMERID,N.SUBTOTAL,N.TAXAMT,N.FREIGHT,N.TOTALDUE,N.PRODUCTNAME,N.DESCRIPTION,N.COLOR,N.SIZE,N.SizeUnitMeasureCode,N.SubCatgoName,N.ProductSubcategoryID,N.CategoryName,N.ProductCategoryID,N.TerritoryName,N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID,N.REPORT_DATE )end caseendDBA TERRITORYRPT_GB Territory_ReportGB INSERT AFTER create trigger TERRITORYRPT_GB after insert onDBA.Territory_ReportGBreferencing new as Nfor each rowbeginset self_recursion off;insert into REPORT_ADUIT( SalesOrderNumber,AccountNumber,ORDERDATE,DUEDATE,SHIPDATE,PRODUCTID,CUSTOMERID,SUBTOTAL,TAXAMT,FREIGHT,TOTALDUE,PRODUCTNAME,DESCRIPTION,COLOR,SIZE,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID,REPORT_ID,REPORT_DATE ) values( N.SalesOrderNumber,N.AccountNumber,N.ORDERDATE,N.DUEDATE,N.SHIPDATE,N.PRODUCTID,N.CUSTOMERID,N.SUBTOTAL,N.TAXAMT,N.FREIGHT,N.TOTALDUE,N.PRODUCTNAME,N.DESCRIPTION,N.COLOR,N.SIZE,N.SizeUnitMeasureCode,N.SubCatgoName,N.ProductSubcategoryID,N.CategoryName,N.ProductCategoryID,N.TerritoryName,N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID,N.REPORT_DATE )endselect * from sysprocedure where PROC_NAME =ProdHistory ORPROC_NAME =eMPaGEproc_id creator object_id proc_name proc_defn remarks replicate srvid source avg_num_rows avg_cost stats351 1 4388 EMPAGE create function DBA.EMPAGE( in @SNN integer )returns integerbegindeclare @EMPAGE1 integer;select DATEDIFF(yy,HRE.BirthDate,current timestamp) as EAGEinto @EMPAGE1 from HumanResources.Employee as HREwhere HRE.NationalIDNumber = @SNN;return(@EMPAGE1)endN create FUNCTION EMPAGE( in @SNN integer)RETURNS INTEGERBEGINDECLARE @EMPAGE1 integer;SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGEINTO@EMPAGE1FROM HumanResources.Employee HREWHERE HRE.NationalIDNumber = @SNN;RETURN (@EMPAGE1);ENDBinary DataRemote Server
  • 30. 29CREATE SERVER "MYSQL4" CLASS MYSQLODBC USING Mysql-Sakila;CREATE EXTERNLOGIN "DBA" TO "MYSQL4" REMOTE LOGIN root IDENTIFIED BY ***;CREATE SERVER "DB2" CLASS DB2ODBC USING GSDB;CREATE EXTERNLOGIN "DBA" TO "DB2" REMOTE LOGIN GOC-PC IDENTIFIED BY ***;A proxy table is needed to access the data in a remote server.
  • 31. 30SELECT * FROM "DBA"."customer"customer_id store_id first_name last_name email address_id active create_date last_update1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0002 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0003 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0004 2 BARBARA JONES BARBARA.JONES@sakilacustomer.org 8 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0005 1 ELIZABETH BROWN ELIZABETH.BROWN@sakilacustomer.org 9 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0006 2 JENNIFER DAVIS JENNIFER.DAVIS@sakilacustomer.org 10 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0007 1 MARIA MILLER MARIA.MILLER@sakilacustomer.org 11 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.0008 2 SUSAN WILSON SUSAN.WILSON@sakilacustomer.org 12 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000

×