SlideShare a Scribd company logo
1 of 31
Sybase SQL AnyWhere 12
By
Sunny Okoro
1
Contents
Database Platform................................................................................................................................................................... 2
Applications............................................................................................................................................................................... 2
Database Diagram................................................................................................................................................................ 5
Functions..................................................................................................................................................................................... 7
User Defined Function.........................................................................................................................................................10
Stored Procedures.................................................................................................................................................................11
DDL..............................................................................................................................................................................................14
Triggers......................................................................................................................................................................................20
XML..............................................................................................................................................................................................21
Cursors.......................................................................................................................................................................................22
DBA..............................................................................................................................................................................................24
2
Database Platform
Sybase SQLAnyWhere 12
Applications
Sybase Central
Sybase PowerDesigner
3
Microsoft Excel and Power Pivot
Microsoft Visual Studio 2012
4
Sybase InfoMaker 11
5
Database Diagram
Captured from Sybase PowerDesigner 16
6
FK_Store_SalesPerson_SalesPersonID
FK_Store_BusinessEntity_BusinessEntityID
FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID
FK_SpecialOfferProduct_Product_ProductID
FK_ShoppingCartItem_Product_ProductID
FK_SalesTerritoryHistory_SalesTerritory_TerritoryID
FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID
FK_SalesTerritory_CountryRegion_CountryRegionCode
FK_SalesTaxRate_StateProvince_StateProvinceID
FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID
FK_SalesPerson_SalesTerritory_TerritoryID
FK_SalesPerson_Employee_BusinessEntityID
FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID
FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID
FK_SalesOrderHeader_SalesTerritory_TerritoryID
FK_SalesOrderHeader_ShipMethod_ShipMethodID
FK_SalesOrderHeader_SalesPerson_SalesPersonID
FK_SalesOrderHeader_Customer_CustomerID
FK_SalesOrderHeader_CurrencyRate_CurrencyRateID
FK_SalesOrderHeader_CreditCard_CreditCardID
FK_SalesOrderHeader_Address_ShipToAddressID
FK_SalesOrderHeader_Address_BillToAddressID
FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID
FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID
FK_PersonCreditCard_CreditCard_CreditCardID
FK_PersonCreditCard_Person_BusinessEntityID
FK_Customer_SalesTerritory_TerritoryID
FK_Customer_Store_StoreID
FK_Customer_Person_PersonID
FK_CurrencyRate_Currency_ToCurrencyCode
FK_CurrencyRate_Currency_FromCurrencyCode
FK_CountryRegionCurrency_Currency_CurrencyCode
FK_CountryRegionCurrency_CountryRegion_CountryRegionCode
FK_Vendor_BusinessEntity_BusinessEntityID
FK_PurchaseOrderHeader_ShipMethod_ShipMethodID
FK_PurchaseOrderHeader_Vendor_VendorID
FK_PurchaseOrderHeader_Employee_EmployeeID
FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID
FK_PurchaseOrderDetail_Product_ProductID
FK_ProductVendor_Vendor_BusinessEntityID
FK_ProductVendor_UnitMeasure_UnitMeasureCode
FK_ProductVendor_Product_ProductID
FK_WorkOrderRouting_WorkOrder_WorkOrderID
FK_WorkOrderRouting_Location_LocationID
FK_WorkOrder_ScrapReason_ScrapReasonID
FK_WorkOrder_Product_ProductID
FK_TransactionHistory_Product_ProductID
FK_ProductSubcategory_ProductCategory_ProductCategoryID
FK_ProductReview_Product_ProductID
FK_ProductProductPhoto_ProductPhoto_ProductPhotoID
FK_ProductProductPhoto_Product_ProductID
FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID
FK_ProductModelProductDescriptionCulture_Culture_CultureID
FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID
FK_ProductModelIllustration_Illustration_IllustrationID
FK_ProductModelIllustration_ProductModel_ProductModelID
FK_ProductListPriceHistory_Product_ProductID
FK_ProductInventory_Product_ProductID
FK_ProductInventory_Location_LocationID
FK_ProductDocument_Document_DocumentNodeID
FK_ProductDocument_Product_ProductID
FK_ProductCostHistory_Product_ProductID
FK_Product_ProductSubcategory_ProductSubcategoryID
FK_Product_ProductModel_ProductModelID
FK_Product_UnitMeasure_WeightUnitMeasureCode
FK_Product_UnitMeasure_SizeUnitMeasureCode
FK_Document_Employee_Owner
FK_BillOfMaterials_UnitMeasure_UnitMeasureCode
FK_BillOfMaterials_Product_ComponentID
FK_BillOfMaterials_Product_ProductAssemblyID
FK_StateProvince_SalesTerritory_TerritoryID
FK_StateProvince_CountryRegion_CountryRegionCode
FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID
FK_PersonPhone_Person_BusinessEntityID
FK_Person_BusinessEntity_BusinessEntityID
FK_Password_Person_BusinessEntityID
FK_EmailAddress_Person_BusinessEntityID
FK_BusinessEntityContact_BusinessEntity_BusinessEntityID
FK_BusinessEntityContact_ContactType_ContactTypeID
FK_BusinessEntityContact_Person_PersonID FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID
FK_BusinessEntityAddress_AddressType_AddressTypeID
FK_BusinessEntityAddress_Address_AddressID
FK_Address_StateProvince_StateProvinceID
FK_JobCandidate_Employee_BusinessEntityID
FK_EmployeePayHistory_Employee_BusinessEntityID
FK_EmployeeDepartmentHistory_Shift_ShiftID
FK_EmployeeDepartmentHistory_Employee_BusinessEntityID
FK_EmployeeDepartmentHistory_Department_DepartmentID
FK_Employee_Person_BusinessEntityID
Document
DocumentNodeID
Title
Owner
FolderFlag
FileName
FileExtension
Revision
ChangeNumber
Status
DocumentSummary
Document
rowguid
ModifiedDate
integer
nvarchar
integer
bit
nvarchar
nvarchar
nchar
integer
tinyint
nvarchar
varbinary(32767)
uniqueidentifier
timestamp
<pk>
<fk>
<ak>
Culture
CultureID
Name
ModifiedDate
nchar
nvarchar
timestamp
<pk>
BillOfMaterials
BillOfMaterialsID
ProductAssemblyID
ComponentID
StartDate
EndDate
UnitMeasureCode
BOMLevel
PerAssemblyQty
ModifiedDate
integer
integer
integer
timestamp
timestamp
nchar
smallint
decimal(8,2)
timestamp
<pk>
<fk1>
<fk2>
<fk3>
StateProvince
StateProvinceID
StateProvinceCode
CountryRegionCode
IsOnlyStateProvinceFlag
Name
TerritoryID
rowguid
ModifiedDate
integer
nchar
nvarchar
bit
nvarchar
integer
uniqueidentifier
timestamp
<pk>
<fk1>
<fk2>
PhoneNumberType
PhoneNumberTypeID
Name
ModifiedDate
integer
nvarchar
timestamp
<pk>
PersonPhone
BusinessEntityID
PhoneNumber
PhoneNumberTypeID
ModifiedDate
integer
nvarchar
integer
timestamp
<pk,fk1>
<pk>
<pk,fk2>
Person
BusinessEntityID
PersonType
NameStyle
Title
FirstName
MiddleName
LastName
Suffix
EmailPromotion
AdditionalContactInfo
Demographics
rowguid
ModifiedDate
integer
nchar
bit
nvarchar
nvarchar
nvarchar
nvarchar
nvarchar
integer
xml
xml
uniqueidentifier
timestamp
<pk,fk>
Password
BusinessEntityID
PasswordHash
PasswordSalt
rowguid
ModifiedDate
integer
varchar(128)
varchar(10)
uniqueidentifier
timestamp
<pk,fk>
EmailAddress
BusinessEntityID
EmailAddressID
EmailAddress
rowguid
ModifiedDate
integer
integer
nvarchar
uniqueidentifier
timestamp
<pk,fk>
<pk>
CountryRegion
CountryRegionCode
Name
ModifiedDate
nvarchar
nvarchar
timestamp
<pk>
ContactType
ContactTypeID
Name
ModifiedDate
integer
nvarchar
timestamp
<pk>
BusinessEntityContact
BusinessEntityID
PersonID
ContactTypeID
rowguid
ModifiedDate
integer
integer
integer
uniqueidentifier
timestamp
<pk,fk3>
<pk,fk1>
<pk,fk2> BusinessEntityAddress
BusinessEntityID
AddressID
AddressTypeID
rowguid
ModifiedDate
integer
integer
integer
uniqueidentifier
timestamp
<pk,fk3>
<pk,fk1>
<pk,fk2>
BusinessEntity
BusinessEntityID
rowguid
ModifiedDate
integer
uniqueidentifier
timestamp
<pk>
AddressType
AddressTypeID
Name
rowguid
ModifiedDate
integer
nvarchar
uniqueidentifier
timestamp
<pk>
Address
AddressID
AddressLine1
AddressLine2
City
StateProvinceID
PostalCode
SpatialLocation
rowguid
ModifiedDate
integer
nvarchar
nvarchar
nvarchar
integer
nvarchar
st_geometry(32767)
uniqueidentifier
timestamp
<pk>
<fk>
Shift
ShiftID
Name
StartTime
EndTime
ModifiedDate
tinyint
nvarchar
time
time
timestamp
<pk>
JobCandidate
JobCandidateID
BusinessEntityID
Resume
ModifiedDate
integer
integer
xml
timestamp
<pk>
<fk>
EmployeePayHistory
BusinessEntityID
RateChangeDate
Rate
PayFrequency
ModifiedDate
integer
timestamp
numeric(19,4)
tinyint
timestamp
<pk,fk>
<pk>
EmployeeDepartmentHistory
BusinessEntityID
DepartmentID
ShiftID
StartDate
EndDate
ModifiedDate
integer
smallint
tinyint
date
date
timestamp
<pk,fk2>
<pk,fk1>
<pk,fk3>
<pk>
Employee
BusinessEntityID
NationalIDNumber
LoginID
JobTitle
BirthDate
MaritalStatus
Gender
HireDate
SalariedFlag
VacationHours
SickLeaveHours
CurrentFlag
rowguid
ModifiedDate
integer
nvarchar
nvarchar
nvarchar
date
nchar
nchar
date
bit
smallint
smallint
bit
uniqueidentifier
timestamp
<pk,fk>
Department
DepartmentID
Name
GroupName
ModifiedDate
smallint
nvarchar
nvarchar
timestamp
<pk>
Illustration
IllustrationID
Diagram
ModifiedDate
integer
xml
timestamp
<pk>
Location
LocationID
Name
CostRate
Availability
ModifiedDate
smallint
nvarchar
numeric(10,4)
decimal(8,2)
timestamp
<pk>
Product
ProductID
ProductNumber
MakeFlag
FinishedGoodsFlag
Name
Color
SafetyStockLevel
ReorderPoint
ListPrice
Size
SizeUnitMeasureCode
StandardCost
WeightUnitMeasureCode
Weight
DaysToManufacture
ProductLine
Class
Style
ProductSubcategoryID
ProductModelID
SellStartDate
SellEndDate
DiscontinuedDate
rowguid
ModifiedDate
integer
nvarchar
bit
bit
nvarchar
nvarchar
smallint
smallint
numeric(19,4)
nvarchar
nchar
numeric(19,4)
nchar
decimal(8,2)
integer
nchar
nchar
nchar
integer
integer
timestamp
timestamp
timestamp
uniqueidentifier
timestamp
<pk>
<fk1>
<fk2>
<fk4>
<fk3>
ProductCategory
ProductCategoryID
Name
rowguid
ModifiedDate
integer
nvarchar
uniqueidentifier
timestamp
<pk>
ProductCostHistory
ProductID
StartDate
EndDate
StandardCost
ModifiedDate
integer
timestamp
timestamp
numeric(19,4)
timestamp
<pk,fk>
<pk>
ProductDescription
ProductDescriptionID
Description
rowguid
ModifiedDate
integer
nvarchar
uniqueidentifier
timestamp
<pk>
ProductDocument
ProductID
DocumentNodeID
ModifiedDate
integer
integer
timestamp
<pk,fk1>
<pk,fk2>
ProductInventory
ProductID
LocationID
Shelf
Bin
Quantity
rowguid
ModifiedDate
integer
smallint
nvarchar
tinyint
smallint
uniqueidentifier
timestamp
<pk,fk2>
<pk,fk1>
ProductListPriceHistory
ProductID
StartDate
EndDate
ListPrice
ModifiedDate
integer
timestamp
timestamp
numeric(19,4)
timestamp
<pk,fk>
<pk>
ProductModel
ProductModelID
Name
CatalogDescription
Instructions
rowguid
ModifiedDate
integer
nvarchar
xml
xml
uniqueidentifier
timestamp
<pk>
ProductModelIllustration
ProductModelID
IllustrationID
ModifiedDate
integer
integer
timestamp
<pk,fk1>
<pk,fk2>
ProductModelProductDescriptionCulture
ProductModelID
ProductDescriptionID
CultureID
ModifiedDate
integer
integer
nchar
timestamp
<pk,fk3>
<pk,fk1>
<pk,fk2>
ProductPhoto
ProductPhotoID
ThumbNailPhoto
ThumbnailPhotoFileName
LargePhoto
LargePhotoFileName
ModifiedDate
integer
varbinary(32767)
nvarchar
varbinary(32767)
nvarchar
timestamp
<pk>
ProductProductPhoto
ProductID
ProductPhotoID
Primary
ModifiedDate
integer
integer
bit
timestamp
<pk,fk1>
<pk,fk2>
ProductReview
ProductReviewID
ProductID
ReviewerName
ReviewDate
EmailAddress
Rating
Comments
ModifiedDate
integer
integer
nvarchar
timestamp
nvarchar
integer
nvarchar
timestamp
<pk>
<fk>
ProductSubcategory
ProductSubcategoryID
ProductCategoryID
Name
rowguid
ModifiedDate
integer
integer
nvarchar
uniqueidentifier
timestamp
<pk>
<fk>
ScrapReason
ScrapReasonID
Name
ModifiedDate
smallint
nvarchar
timestamp
<pk>
TransactionHistory
TransactionID
ProductID
ReferenceOrderID
ReferenceOrderLineID
TransactionDate
TransactionType
Quantity
ActualCost
ModifiedDate
integer
integer
integer
integer
timestamp
nchar
integer
numeric(19,4)
timestamp
<pk>
<fk>
UnitMeasure
UnitMeasureCode
Name
ModifiedDate
nchar
nvarchar
timestamp
<pk>
WorkOrder
WorkOrderID
ProductID
OrderQty
StockedQty
ScrappedQty
StartDate
EndDate
DueDate
ScrapReasonID
ModifiedDate
integer
integer
integer
integer
smallint
timestamp
timestamp
timestamp
smallint
timestamp
<pk>
<fk1>
<fk2>
WorkOrderRouting
WorkOrderID
ProductID
OperationSequence
LocationID
ScheduledStartDate
ScheduledEndDate
ActualStartDate
ActualEndDate
ActualResourceHrs
PlannedCost
ActualCost
ModifiedDate
integer
integer
smallint
smallint
timestamp
timestamp
timestamp
timestamp
decimal(9,4)
numeric(19,4)
numeric(19,4)
timestamp
<pk,fk2>
<pk>
<pk>
<fk1>
ProductVendor
ProductID
BusinessEntityID
AverageLeadTime
StandardPrice
LastReceiptCost
LastReceiptDate
MinOrderQty
MaxOrderQty
OnOrderQty
UnitMeasureCode
ModifiedDate
integer
integer
integer
numeric(19,4)
numeric(19,4)
timestamp
integer
integer
integer
nchar
timestamp
<pk,fk1>
<pk,fk3>
<fk2>
PurchaseOrderDetail
PurchaseOrderID
PurchaseOrderDetailID
DueDate
OrderQty
ProductID
UnitPrice
LineTotal
ReceivedQty
RejectedQty
StockedQty
ModifiedDate
integer
integer
timestamp
smallint
integer
numeric(19,4)
numeric(19,4)
decimal(8,2)
decimal(8,2)
decimal
timestamp
<pk,fk2>
<pk>
<fk1>
PurchaseOrderHeader
PurchaseOrderID
RevisionNumber
Status
EmployeeID
VendorID
ShipMethodID
OrderDate
ShipDate
SubTotal
TaxAmt
Freight
TotalDue
ModifiedDate
integer
tinyint
tinyint
integer
integer
integer
timestamp
timestamp
numeric(19,4)
numeric(19,4)
numeric(19,4)
numeric(19,4)
timestamp
<pk>
<fk1>
<fk2>
<fk3>
ShipMethod
ShipMethodID
Name
ShipBase
ShipRate
rowguid
ModifiedDate
integer
nvarchar
numeric(19,4)
numeric(19,4)
uniqueidentifier
timestamp
<pk>
Vendor
BusinessEntityID
AccountNumber
Name
CreditRating
PreferredVendorStatus
ActiveFlag
PurchasingWebServiceURL
ModifiedDate
integer
nvarchar
nvarchar
tinyint
bit
bit
nvarchar
timestamp
<pk,fk>
CountryRegionCurrency
CountryRegionCode
CurrencyCode
ModifiedDate
nvarchar
nchar
timestamp
<pk,fk1>
<pk,fk2>
CreditCard
CreditCardID
CardType
CardNumber
ExpMonth
ExpYear
ModifiedDate
integer
nvarchar
nvarchar
tinyint
smallint
timestamp
<pk>
Currency
CurrencyCode
Name
ModifiedDate
nchar
nvarchar
timestamp
<pk>
CurrencyRate
CurrencyRateID
CurrencyRateDate
FromCurrencyCode
ToCurrencyCode
AverageRate
EndOfDayRate
ModifiedDate
integer
timestamp
nchar
nchar
numeric(19,4)
numeric(19,4)
timestamp
<pk>
<fk1>
<fk2>
Customer
CustomerID
PersonID
StoreID
TerritoryID
AccountNumber
rowguid
ModifiedDate
integer
integer
integer
integer
varchar(10)
uniqueidentifier
timestamp
<pk>
<fk1>
<fk2>
<fk3>
PersonCreditCard
BusinessEntityID
CreditCardID
ModifiedDate
integer
integer
timestamp
<pk,fk1>
<pk,fk2>
SalesOrderDetail
SalesOrderID
SalesOrderDetailID
CarrierTrackingNumber
OrderQty
ProductID
SpecialOfferID
UnitPrice
UnitPriceDiscount
LineTotal
rowguid
ModifiedDate
integer
integer
nvarchar
smallint
integer
integer
numeric(19,4)
numeric(19,4)
numeric(19,4)
uniqueidentifier
timestamp
<pk,fk1>
<pk>
<fk2>
<fk2>
SalesOrderHeader
SalesOrderID
RevisionNumber
OrderDate
DueDate
ShipDate
Status
OnlineOrderFlag
SalesOrderNumber
ShipMethodID
PurchaseOrderNumber
AccountNumber
CustomerID
SalesPersonID
TerritoryID
BillToAddressID
ShipToAddressID
CreditCardID
CreditCardApprovalCode
CurrencyRateID
SubTotal
TaxAmt
Freight
TotalDue
Comment
rowguid
ModifiedDate
integer
tinyint
timestamp
timestamp
timestamp
tinyint
bit
nvarchar
integer
nvarchar
nvarchar
integer
integer
integer
integer
integer
integer
varchar(15)
integer
numeric(19,4)
numeric(19,4)
numeric(19,4)
numeric(19,4)
nvarchar
uniqueidentifier
timestamp
<pk>
<fk7>
<fk5>
<fk6>
<fk8>
<fk1>
<fk2>
<fk3>
<fk4>
SalesOrderHeaderSalesReason
SalesOrderID
SalesReasonID
ModifiedDate
integer
integer
timestamp
<pk,fk2>
<pk,fk1>
SalesPerson
BusinessEntityID
TerritoryID
SalesQuota
Bonus
CommissionPct
SalesYTD
SalesLastYear
rowguid
ModifiedDate
integer
integer
numeric(19,4)
numeric(19,4)
numeric(10,4)
numeric(19,4)
numeric(19,4)
uniqueidentifier
timestamp
<pk,fk1>
<fk2>
SalesPersonQuotaHistory
BusinessEntityID
QuotaDate
SalesQuota
rowguid
ModifiedDate
integer
timestamp
numeric(19,4)
uniqueidentifier
timestamp
<pk,fk>
<pk>
SalesReason
SalesReasonID
Name
ReasonType
ModifiedDate
integer
nvarchar
nvarchar
timestamp
<pk>
SalesTaxRate
SalesTaxRateID
StateProvinceID
TaxType
TaxRate
Name
rowguid
ModifiedDate
integer
integer
tinyint
numeric(10,4)
nvarchar
uniqueidentifier
timestamp
<pk>
<fk>
SalesTerritory
TerritoryID
Name
CountryRegionCode
Group
SalesYTD
SalesLastYear
CostYTD
CostLastYear
rowguid
ModifiedDate
integer
nvarchar
nvarchar
nvarchar
numeric(19,4)
numeric(19,4)
numeric(19,4)
numeric(19,4)
uniqueidentifier
timestamp
<pk>
<fk>
SalesTerritoryHistory
BusinessEntityID
TerritoryID
StartDate
EndDate
rowguid
ModifiedDate
integer
integer
timestamp
timestamp
uniqueidentifier
timestamp
<pk,fk1>
<pk,fk2>
<pk>
ShoppingCartItem
ShoppingCartItemID
ShoppingCartID
Quantity
ProductID
DateCreated
ModifiedDate
integer
nvarchar
integer
integer
timestamp
timestamp
<pk>
<fk>
SpecialOffer
SpecialOfferID
Description
DiscountPct
Type
Category
StartDate
EndDate
MinQty
MaxQty
rowguid
ModifiedDate
integer
nvarchar
numeric(10,4)
nvarchar
nvarchar
timestamp
timestamp
integer
integer
uniqueidentifier
timestamp
<pk>
SpecialOfferProduct
SpecialOfferID
ProductID
rowguid
ModifiedDate
integer
integer
uniqueidentifier
timestamp
<pk,fk2>
<pk,fk1>
Store
BusinessEntityID
Name
SalesPersonID
Demographics
rowguid
ModifiedDate
integer
nvarchar
integer
xml
uniqueidentifier
timestamp
<pk,fk1>
<fk2>
7
Functions
SELECT 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 OrderDate
FROM Sales.Customer c
inner join
Sales.SalesOrderHeader soh
on c.CustomerID = soh.CustomerID
inner join
Sales.SalesOrderDetail sod
on soh.SalesOrderID = sod.SalesOrderID
CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID CreditCardID SubTotal Freight TaxAmt TotalDue OrderDate
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001
Results Abridged
SELECT string(LastName, FirstName) AS Person_Name, lastName||','||firstName as Person_Name2
FROM Person.Person
Person_Name Person_Name2
SánchezKen Sánchez,Ken
DuffyTerri Duffy,Terri
TamburelloRoberto Tamburello,Roberto
WaltersRob Walters,Rob
EricksonGail Erickson,Gail
GoldbergJossef Goldberg,Jossef
Results Abridged
SELECT 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 OrderDate
FROM Sales.Customer c
inner join
Sales.SalesOrderHeader soh
on c.CustomerID = soh.CustomerID
inner join
Sales.SalesOrderDetail sod
on soh.SalesOrderID = sod.SalesOrderID
CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID SubTotal Freight TaxAmt TotalDue OrderDate
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3
29672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,3
29672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,3
29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3
29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3
29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3
29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3
29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3
Results Abridged
SELECT 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 OrderDate
FROM Sales.Customer c
inner join
Sales.SalesOrderHeader soh
8
on c.CustomerID = soh.CustomerID
inner join
Sales.SalesOrderDetail sod
on soh.SalesOrderID = sod.SalesOrderID
inner join Sales.SalesTerritory j
on
soh.TerritoryID = j.TerritoryID
CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryName ShipMethodID Subtotal Freight TaxAmt TotalDue2 TotalDue OrderDate
29614 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,3
29614 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,3
29614 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,3
29614 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,3
29614 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,3
29614 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,3
29614 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,3
29747 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,3
29566 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,3
29566 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,3
29566 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,3
29566 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,3
29890 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,3
29890 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,3
29890 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,3
Results Abridged
SELECT string(LastName, FirstName) AS Person_Name, UPPER (lastName)||','|| LOWER(firstName) as Person_Name2
FROM Person.Person
Person_Name Person_Name2
SánchezKen SÁNCHEZ,ken
DuffyTerri DUFFY,terri
TamburelloRoberto TAMBURELLO,roberto
WaltersRob WALTERS,rob
EricksonGail ERICKSON,gail
GoldbergJossef GOLDBERG,jossef
MillerDylan MILLER,dylan
MargheimDiane MARGHEIM,diane
MatthewGigi MATTHEW,gigi
RaheemMichael RAHEEM,michael
CraciumOvidiu CRACIUM,ovidiu
D'HersThierry D'HERS,thierry
GalvinJanice GALVIN,janice
SullivanMichael SULLIVAN,michael
SalavariaSharon SALAVARIA,sharon
BradleyDavid BRADLEY,david
BrownKevin BROWN,kevin
WoodJohn WOOD,john
DempseyMary DEMPSEY,mary
BenshoofWanida BENSHOOF,wanida
EminhizerTerry EMINHIZER,terry
HarnpadoungsatayaSariya HARNPADOUNGSATAYA,sariya
Results Abridged
WITH ORDERS4(CUSTOMER_ID,TOTAL_DUE)
AS(SELECT CUSTOMERID AS CUSTOMER_ID, TotalDue AS TOTAL_DUE
FROM ORDERS)
SELECT DISTINCT (CUSTOMER_ID)as CUSTOMER_ID, cast(TOTAL_DUE as decimal (23,2))as TOTAL_DUE
FROM
ORDERS4
WHERE TOTAL_DUE <> (SELECT cast (max(TotalDue)as decimal (23,2)) FROM ORDERS)
CUSTOMER_ID TOTAL_DUE
29825 27231.55
29672 1716.18
29734 43561.44
29994 38331.96
29565 556.20
29898 32390.20
29580 19005.21
30052 6718.05
29974 8095.79
29614 47815.63
29747 974.02
29566 8115.68
29890 10784.99
Results Abridged
SELECT HRE.BusinessEntityID, HRE.BirthDate, HRE.Gender, HRE.MaritalStatus, HRE.NationalIDNumber,
HRE.SickLeaveHours, HRE.VacationHours,
DATEDIFF(YY, BirthDate , CURRENT_TIMESTAMP) AS AGE
9
FROM HumanResources.Employee HRE
BusinessEntityID BirthDate Gender MaritalStatus NationalIDNumber SickLeaveHours VacationHours AGE
1 1959-03-02 M S 295847284 69 99 54
2 1961-09-01 F S 245797967 20 1 52
3 1964-12-13 M M 509647174 21 2 49
4 1965-01-23 M S 112457891 80 48 48
5 1942-10-29 F M 695256908 22 5 71
6 1949-04-11 M M 998320692 23 6 64
7 1977-03-27 M M 134969118 50 61 36
8 1976-07-06 F S 811994146 51 62 37
9 1969-02-21 F M 658797903 51 63 44
10 1975-01-01 M M 879342154 64 16 38
11 1968-02-18 M S 974026903 23 7 45
12 1949-08-29 M M 480168528 24 9 64
13 1979-06-29 F M 486228782 24 8 34
14 1969-07-17 M S 42487730 21 3 44
15 1951-06-03 F M 56920285 22 4 62
16 1965-04-19 M S 24756624 40 40 48
17 1977-06-03 M S 253022876 41 42 36
Results Abridged
SELECT 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 TerritoryGroup
FROM Sales.SalesOrderHeader SOH
INNER JOIN
Sales.Customer SC
ON
SOH. CUSTOMERID = SC.CUSTOMERID
INNER JOIN
Sales.CreditCard SCC
ON
SCC.CREDITCARDID = SOH.CREDITCARDID
INNER JOIN
SALES.CurrencyRate SCR
ON
SOH.CurrencyRateID = SCR.CurrencyRateID
INNER JOIN
SALES.SalesTerritory STR
ON
STR.TerritoryID = SOH.TerritoryID
INNER JOIN
SALES.Currency SCY
ON
SCY.CurrencyCode = SCR.FromCurrencyCode
OR
SCY.CurrencyCode = SCR.ToCurrencyCode
CustomerID OrderDate SalesOrderID Freight TaxAmt TotalDue CardType CardNum EXP_DATE Currency_Name CountryRegionCode Territory_Name TerritoryGroup
29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 US Dollar CA Canada North America
29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 Canadian Dollar CA Canada North America
29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 US Dollar CA Canada North America
29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 Canadian Dollar CA Canada North America
29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 US Dollar CA Canada North America
29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 Canadian Dollar CA Canada North America
30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 US Dollar CA Canada North America
30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 Canadian Dollar CA Canada North America
29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 US Dollar CA Canada North America
29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 Canadian Dollar CA Canada North America
29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 US Dollar CA Canada North America
29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 Canadian Dollar CA Canada North America
29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 US Dollar CA Canada North America
29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 Canadian Dollar CA Canada North America
21768 2001-07-01 43697 89.46 286.26 3953.99 SuperiorCard 0x477e43dc99fc3fc8e8dc127b735cf3c51b37b17addfb8f0064d3e3c2fffc0d0e 7-2008 US Dollar CA Canada North America
Results Abridged
SELECT 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_Name
FROM Sales.SalesOrderHeader SOH
INNER JOIN
SALES.SalesTerritory STR
ON
STR.TerritoryID = SOH.TerritoryID
where STR.CountryRegionCode = 'US'
10
SalesOrderID CustomerID TotalDue CountryRegionCode Territory_Name TerritoryGroup TOTAL_Territor_Sales_Region TOTAL_Territor_Sales_Group TOTAL_Territor_Sales_Name
66560 21246 1320.44 US Southwest North America 82425339.37 82425339.37 31213458.71
70656 24831 2649.85 US Southwest North America 82425339.37 82425339.37 31213458.71
70912 17441 2657.47 US Southwest North America 82425339.37 82425339.37 31213458.71
44544 29522 27847.06 US Southwest North America 82425339.37 82425339.37 31213458.71
45568 29637 20205.63 US Southwest North America 82425339.37 82425339.37 31213458.71
46336 29944 556.20 US Southwest North America 82425339.37 82425339.37 31213458.71
47104 13279 2410.63 US Southwest North America 82425339.37 82425339.37 31213458.71
47360 29696 1051.23 US Southwest North America 82425339.37 82425339.37 31213458.71
48128 26534 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.71
48384 29562 90625.93 US Southwest North America 82425339.37 82425339.37 31213458.71
48640 26681 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.71
49152 29792 30842.05 US Southwest North America 82425339.37 82425339.37 31213458.71
49408 15535 865.20 US Southwest North America 82425339.37 82425339.37 31213458.71
50688 29793 77584.01 US Southwest North America 82425339.37 82425339.37 31213458.71
51968 13171 132.60 US Southwest North America 82425339.37 82425339.37 31213458.71
55296 29850 2916.30 US Southwest North America 82425339.37 82425339.37 31213458.71
57344 12047 38.68 US Southwest North America 82425339.37 82425339.37 31213458.71
58368 25208 30.14 US Southwest North America 82425339.37 82425339.37 31213458.71
60160 13454 2590.41 US Southwest North America 82425339.37 82425339.37 31213458.71
Results Abridged
User Defined Function
CREATE OR REPLACE FUNCTION EMPAGE( )
RETURNS INTEGER
BEGIN
SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE
FROM HumanResources.Employee HRE
END;
SELECT SELECT "DBA"."EMPAGE"();
CREATE OR REPLACE FUNCTION EMPAGE( in @SNN integer)
RETURNS INTEGER
BEGIN
DECLARE @EMPAGE1 integer;
SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE
INTO
@EMPAGE1
FROM HumanResources.Employee HRE
WHERE HRE.NationalIDNumber = @SNN;
RETURN (@EMPAGE1);
END;
SELECT "DBA"."EMPAGE"(509647174 ) AS EMP_AGE;
11
Stored Procedures
CREATE OR REPLACE PROCEDURE SalesTerritory_Report
(@Region_Code Char(8))
AS
SELECT 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.TerritoryID
FROM Sales.SalesOrderDetail SOD
INNER JOIN Sales.SalesOrderHeader SOH
ON
SOD.SalesOrderID = SOH.SalesOrderID
INNER JOIN Production.Product PD
ON SOD.PRODUCTID = PD.PRODUCTID
INNER JOIN
SALES.SalesTerritory ST
ON
SOH.TerritoryID = ST.TerritoryID
where CountryRegionCode = @Region_Code
ORDER BY PD.NAME;
EXEC SalesTerritory_Report('GB')
SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID
SO73803 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
SO70784 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 10
SO71313 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 10
SO74525 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 10
SO69201 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 10
SO69205 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 10
SO55484 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 10
SO60357 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 10
SO57657 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 10
SO64640 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 10
SO62727 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 10
SO56027 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 10
SO59644 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 10
SO57775 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 10
SO64183 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 10
Results Abridged
CREATE OR REPLACE PROCEDURE PRODUCTS()
AS
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,
PPD.Description,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
12
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
exec PRODUCTS;
ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name
680 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 Frames
706 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 Frames
707 Sport-100 Helmet, Red Red Universal fit, well-vented, lightweight , snap-on visor. Helmets
708 Sport-100 Helmet, Black Black Universal fit, well-vented, lightweight , snap-on visor. Helmets
709 Mountain Bike Socks, M White M Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks
710 Mountain Bike Socks, L White L Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks
711 Sport-100 Helmet, Blue Blue Universal fit, well-vented, lightweight , snap-on visor. Helmets
712 AWC Logo Cap Multi Traditional style with a flip-up brim; one-size fits all. Caps
713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
717 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 Frames
718 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 Frames
719 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 Frames
720 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 Frames
721 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 Frames
Results Abridged
CREATE OR REPLACE PROCEDURE PRODUCTS2
(@sub_catgo_name char(35)
)
AS
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,
PPD.Description,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PSC.NAME = @sub_catgo_name;
Exec PRODUCTS2( ‘Jerseys’);
ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name
713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys
881 Short-Sleeve Classic Jersey, S Yellow S Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys
882 Short-Sleeve Classic Jersey, M Yellow M Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys
883 Short-Sleeve Classic Jersey, L Yellow L Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys
884 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(
13
in @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--
begin
CASE WHEN @COUNTRYCODE = 'GB'
THEN
select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,
CustomerID,SubTotal,TaxAmt,Freight,TotalDue,
PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,
TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID
from SalesReports
where CountryRegionCode = @COUNTRYCODE
END CASE;
End
EXEC SALES_TERRITORY_GB('US')
Execution time: 0.064 seconds
EXEC SALES_TERRITORY_GB('UK')
SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID
SO73803 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
SO70784 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 10
SO71313 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 10
SO74525 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 10
SO69201 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 10
SO69205 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 10
SO55484 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 10
SO60357 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 10
SO57657 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 10
Results Abridged
CREATE 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--
begin
CASE WHEN @COUNTRYCODE = 'GB'
THEN
select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,
CustomerID,SubTotal,TaxAmt,Freight,TotalDue,
PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID,
TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID
from SalesReports
where CountryRegionCode = @COUNTRYCODE
END CASE;
End
SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID
SO73803 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
14
SO70784 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 10
SO71313 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 10
SO74525 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 10
SO69201 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 10
SO69205 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 10
SO55484 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 10
SO60357 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 10
SO57657 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 10
Results Abridged
DDL
CREATE VIEW ORDERS
AS
SELECT 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 OrderDate
FROM Sales.Customer c
inner join
Sales.SalesOrderHeader soh
on c.CustomerID = soh.CustomerID
inner join
Sales.SalesOrderDetail sod
on soh.SalesOrderID = sod.SalesOrderID
inner join Sales.SalesTerritory j
on
soh.TerritoryID = j.TerritoryID
SELECT 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_DUE2
FROM ORDERS
GROUP BY CustomerID
CUSTOMER_ID AVG_TOTAL_DUE SUM_TOTAL MAX_TOTAL_DUE MIN_TOTAL_DUE
20818 1259.80 7558.83 3953.99 720.97
24921 1254.27 5017.08 1303.87 1105.48
12648 2596.35 20770.84 2699.01 2264.25
16727 2708.69 5417.37 2708.69 2708.69
29012 87.27 174.55 87.27 87.27
12655 2814.05 30954.56 3953.99 2673.06
20817 2275.34 4550.68 3953.99 596.69
24920 1219.70 3659.09 1276.81 1105.48
16726 8.04 16.09 8.04 8.04
29019 1890.64 5671.91 3953.99 858.96
20816 1257.95 7547.72 3953.99 718.75
12654 32.54 130.17 40.08 9.93
24927 211.35 845.41 211.35 211.35
29018 70.69 212.06 70.69 70.69
16725 15.45 30.90 15.45 15.45
29017 3953.99 3953.99 3953.99 3953.99
Results Abridged
SELECT 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.TerritoryID
INTO ORDERS_RECORD
FROM Sales.SalesOrderDetail SOD
INNER JOIN Sales.SalesOrderHeader SOH
ON
SOD.SalesOrderID = SOH.SalesOrderID
INNER JOIN Production.Product PD
ON SOD.PRODUCTID = PD.PRODUCTID
INNER JOIN
SALES.SalesTerritory ST
ON
SOH.TerritoryID = ST.TerritoryID
ORDER BY ST.CountryRegionCode
Note 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_RECORD
SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID
SO43701 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
15
SO43703 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 9
SO43704 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 9
SO43705 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 9
SO43709 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 9
SO43710 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 9
SO43715 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 9
SO43716 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 9
SO43717 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 9
SO43724 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 9
SO43727 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 9
SO43731 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 9
SO43732 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 9
SO43735 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 9
SO43736 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 9
SO43740 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 9
SO43743 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 9
SO43744 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 9
SO43745 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 9
SO43746 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 9
Results Abridged
select top(5) * from ORDERS_RECORD
SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID
SO43701 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
SO43703 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 9
SO43704 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 9
SO43705 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 9
SO43709 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 9
Results 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_ReportGB
ADD CONSTRAINT TERRITRPORT_RPID_PK PRIMARY KEY(REPORT_ID);
ALTER TABLE Territory_ReportGB
add AccountNumber varchar(30);
/* A stored procedure will call this view to populate the report table for GB customers*/
create view SalesReports
AS
SELECT 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.TerritoryID
FROM Sales.SalesOrderDetail SOD
INNER JOIN Sales.SalesOrderHeader SOH
ON
SOD.SalesOrderID = SOH.SalesOrderID
INNER JOIN Production.Product PD
ON SOD.PRODUCTID = PD.PRODUCTID
16
INNER JOIN
SALES.SalesTerritory ST
ON
SOH.TerritoryID = ST.TerritoryID
INNER JOIN
Production.ProductModel PM
ON
PM.ProductModelID = PD.ProductModelID
INNER JOIN
Production. ProductModelProductDescriptionCulture PMPDC
ON
PM.ProductModelID = PMPDC.ProductModelID
INNER JOIN
Production.ProductDescription PPD
ON
PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
INNER JOIN SALES.Customer CU
ON SOH.CustomerID = CU.CustomerID
INNER JOIN
PRODUCTION.ProductCategory PC
ON
PSC.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_ADUIT
ADD CONSTRAINT REPORTAD_ADID_PK PRIMARY KEY(ADUIT_ID);
ALTER TABLE REPORT_ADUIT
add 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),
17
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 ,
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, TerritoryID
FROM SalesReports
WHERE CountryRegionCode ='GB'
select * from REPORT_ADUIT
/*The null column has been removed to allow the report fit to the document*/
SalesOrderNu
mber
ORDERD
ATE
DUEDAT
E
SHIPDA
TE
PRODUC
TID
CUSTOME
RID
SUBTOT
AL
TAXA
MT
FREIG
HT
TOTALD
UE
PRODUCTN
AME
DESCRIPTION COL
OR
SubCatgoN
ame
ProductSubcateg
oryID
CategoryN
ame
ProductCateg
oryID
TerritoryN
ame
CountryRegion
Code
TerritoryGr
oup
Territor
yID
REPORT
_ID
ADUIT
_ID
ADUIT_D
ATE
REPORT_D
ATE
SO57240 11/1/200
3
11/13/2
003
11/8/20
03
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
经典式样,带有翻边;
均码。
Multi Caps 19 Clothing 3 United
Kingdom
GB Europe 10 8 3 5/6/2013
0:02
5/6/2013
0:02
SO57240 11/1/200
3
11/13/2
003
11/8/20
03
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
Multi Caps 19 Clothing 3 United
Kingdom
GB Europe 10 9 4 5/6/2013
0:02
5/6/2013
0:02
Results 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, TerritoryID
FROM SalesReports
WHERE CountryRegionCode ='GB'
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,
18
CustomerID, SubTotal,TaxAmt, Freight, TotalDue,
PRODUCTNAME, "Description","COLOR" ,"Size", SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID,
TerritoryName,CountryRegionCode , TerritoryGroup, TerritoryID
FROM SalesReports
WHERE CountryRegionCode ='US'
select TOP(2) * from
Territory_ReportGB;
SalesOrder
Number
ORDER
DATE
DUED
ATE
SHIPD
ATE
PRODU
CTID
CUSTO
MERID
SUBT
OTAL
TAX
AMT
FREI
GHT
TOTA
LDUE
PRODUC
TNAME
DESCRIPTION COL
OR
SI
ZE
SizeUnitMea
sureCode
SubCatg
oName
ProductSubc
ategoryID
Category
Name
ProductCat
egoryID
Territor
yName
CountryReg
ionCode
Territory
Group
Territo
ryID
REPOR
T_ID
REPORT
_DATE
AccountN
umber
SO51411 2003-07-
15
2003-
07-27
2003-
07-22
712 11239 2353.95 188.3
2
58.85 2601.11 AWC Logo
Cap
经典式样,带有
翻边;均码。
Multi Caps 19 Clothing 3 United
Kingdom
GB Europe 10 88 2013-05-
09
16:55:53.7
63
AW00011
239
SO51411 2003-07-
15
2003-
07-27
2003-
07-22
712 11239 2353.95 188.3
2
58.85 2601.11 AWC Logo
Cap
‫עם‬ ‫מסורתי‬ ‫סגנון‬
‫גודל‬ ;‫מתרוממת‬ ‫מצחייה‬
.‫לכולם‬ ‫מתאים‬ ‫אחד‬
Multi Caps 19 Clothing 3 United
Kingdom
GB Europe 10 89 2013-05-
09
16:55:53.7
64
AW00011
239
select * from Territory_ReportGB
WHERE CountryRegionCode = 'US'
SalesOrderNumber 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 AccountNumber
------------------------- ---------- ---------- ---------- ----------- ----------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------------------- -----------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- --------------- ------------------- -------------------------------------------------- -------------------- -------------------------------------------------- -------
---------- -------------------------------------------------- ----------------- -------------------------------------------------- ----------- ----------- ----------------------- ------------------------------
(0 rows)
Execution time: 0.208 seconds
select TOP(5) * from
Territory_ReportS
WHERE CountryRegionCode ='GB’
SalesOrder
Number
ORDER
DATE
DUED
ATE
SHIPD
ATE
PRODU
CTID
CUSTO
MERID
SUBT
OTAL
TAX
AMT
FREI
GHT
TOTA
LDUE
PRODUC
TNAME
DESCRIPTION COL
OR
SI
ZE
SizeUnitMea
sureCode
SubCatg
oName
ProductSubc
ategoryID
Categor
yName
ProductCat
egoryID
Territor
yName
CountryReg
ionCode
Territory
Group
Territo
ryID
REPO
RT_ID
REPORT
_DATE
AccountN
umber
SO57240 2003-11-
01
2003-
11-13
2003-
11-08
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
经典式样,带有翻边
;均码。
Mult
i
Caps 19 Clothing 3 United
Kingdom
GB Europe 10 4 2013-05-
09
16:55:53.5
52
AW00011
238
SO57240 2003-11-
01
2003-
11-13
2003-
11-08
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
‫מצחייה‬ ‫עם‬ ‫מסורתי‬ ‫סגנון‬
‫מתאים‬ ‫אחד‬ ‫גודל‬ ;‫מתרוממת‬
.‫לכולם‬
Mult
i
Caps 19 Clothing 3 United
Kingdom
GB Europe 10 5 2013-05-
09
16:55:53.6
56
AW00011
238
SO57240 2003-11-
01
2003-
11-13
2003-
11-08
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
Mult
i
Caps 19 Clothing 3 United
Kingdom
GB Europe 10 6 2013-05-
09
16:55:53.6
57
AW00011
238
SO57240 2003-11-
01
2003-
11-13
2003-
11-08
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
Style classique avec
une visière relevable ;
taille unique.
Mult
i
Caps 19 Clothing 3 United
Kingdom
GB Europe 10 7 2013-05-
09
16:55:53.6
60
AW00011
238
SO57240 2003-11-
01
2003-
11-13
2003-
11-08
712 11238 562.96 45.04 14.07 622.07 AWC Logo
Cap
‫رو‬ ‫ٍذي‬ ‫ه‬ ‫ق‬ ‫ت‬ ‫مط‬ ‫و‬ ‫ح‬ ‫حاف‬
،‫هى‬ ‫ألع‬ ‫الب‬‫ق‬ ‫الو‬ ‫ن‬ ‫هح‬ ‫ات‬ ‫ق‬
‫م‬ ‫الئ‬ ٌ ‫واحذ‬ ‫حجم‬ ‫ت‬
.‫ٍع‬ ‫جم‬ ‫ان‬
Mult
i
Caps 19 Clothing 3 United
Kingdom
GB Europe 10 8 2013-05-
09
16:55:53.6
61
AW00011
238
select TOP(5) * from
Territory_ReportS
WHERE CountryRegionCode ='US'
alesOrde
rNumber
ORDE
RDAT
E
DUE
DAT
E
SHIP
DAT
E
PROD
UCTI
D
CUSTO
MERID
SUBT
OTAL
TAX
AMT
FREI
GHT
TOTA
LDUE
PRODU
CTNAM
E
DESCRIPTION CO
LO
R
SI
Z
E
SizeUnitMe
asureCode
SubCat
goName
ProductSub
categoryID
Catego
ryNam
e
ProductC
ategoryID
Territo
ryName
CountryR
egionCode
Territor
yGroup
Territ
oryID
REPO
RT_ID
REPOR
T_DAT
E
Account
Number
SO43670 2001-
07-01
2001-
07-13
2001-
07-08
773 29566 7344.5
0
587.5
6
183.6
1
8115.6
8
Mountain-
100
Silver, 44 HL
Silv
er
44 CM Mountai
n Bikes
1 Bikes 1 Central US North
America
3 62796 2013-05-
09
17:06:14.
134
AW0002
9566
SO43670 2001-
07-01
2001-
07-13
2001-
07-08
773 29566 7344.5
0
587.5
6
183.6
1
8115.6
8
Mountain-
100
Silver, 44
VTT de compétition haut de gamme. Plusieurs
options d'amélioration des performances : cadre HL,
suspension avant particulièrement souple et traction
adaptée à tous les terrains.
Silv
er
44 CM Mountai
n Bikes
1 Bikes 1 Central US North
America
3 62797 2013-05-
09
17:06:14.
134
AW0002
9566
SO43670 2001-
07-01
2001-
07-13
2001-
07-08
773 29566 7344.5
0
587.5
6
183.6
1
8115.6
8
Mountain-
100
Silver, 44
‫هى‬ ‫أع‬ ‫مه‬ ‫ثال‬ ‫ج‬ ‫ان‬ ً ‫ف‬ ‫ٍادج‬ ‫ق‬ ‫ه‬ ‫ن‬ ‫صح‬ ‫ص‬ ‫مخ‬ ‫اخ‬ ‫ثاق‬ ‫س‬ ‫دراجح‬
emarF LH ‫كم‬ ٍ ‫ه‬ ‫األداء‬ ‫ٍه‬ ‫س‬ ‫ح‬ ‫ت‬ ‫ٍاراخ‬ ‫خ‬ ‫ضمه‬ ‫ت‬ ‫ت‬ .‫طراز‬
‫وج‬ ‫وق‬ ،‫قح‬ ‫فائ‬ ‫ان‬ ‫سح‬ ‫ال‬‫س‬ ‫ان‬ ‫ري‬ ً‫ام‬‫األم‬ ‫ٍق‬ ‫ه‬ ‫ع‬‫ت‬ ‫وان‬ ،ً‫ذاع‬ ‫اإلت‬
.ً‫ض‬ ‫األرا‬ ‫واع‬ ‫أو‬ ‫ٍع‬ ‫جم‬ ‫ن‬ ‫ثح‬ ‫س‬ ‫ىا‬ ‫م‬ ‫ان‬ ‫جر‬ ‫ان‬
Silv
er
44 CM Mountai
n Bikes
1 Bikes 1 Central US North
America
3 62798 2013-05-
09
17:06:14.
134
AW0002
9566
19
SO43670 2001-
07-01
2001-
07-13
2001-
07-08
773 29566 7344.5
0
587.5
6
183.6
1
8115.6
8
Mountain-
100
Silver, 44
Top-of-the-line competition mountain bike.
Performance-enhancing options include the
innovative HL Frame, super-smooth front suspension,
and traction for all terrain.
Silv
er
44 CM Mountai
n Bikes
1 Bikes 1 Central US North
America
3 62799 2013-05-
09
17:06:14.
134
AW0002
9566
SO43670 2001-
07-01
2001-
07-13
2001-
07-08
776 29566 7344.5
0
587.5
6
183.6
1
8115.6
8
Mountain-
100
Black, 42
高档竞赛山地车。性能得到进一步增强,包括创
新的 HL
车架、极其平稳的前悬架以及适用于所有地形的
出色牵引力。
Blac
k
42 CM Mountai
n Bikes
1
CREATE or replace VIEW PRODUCTH
AS
SELECT 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_Catego
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
INNER JOIN
PRODUCTION.ProductInventory PPI
ON
PD.ProductID = PPI.ProductID
INNER JOIN
PRODUCTION.ProductCategory PCI
ON
PSC.ProductCategoryID = PCI.ProductCategoryID
CREATE 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
)
BEGIN
IF @ProductID IS NOT NULL
THEN
INSERT 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,
20
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,
ProductCategoryID
FROM PRODUCTH
WHERE ProductID = @ProductID ;
END IF ;
End
SELECT * FROM PRODHISTORY
Product_I
D
Product_Nam
e
Product_Colo
r
Product_Siz
e
SizeUnitMeasur
eCode
Product_Description SubCatgo_Nam
e
Quantit
y
Shel
f
LocationI
D
ModifiedDate_SubCatg
o
P_Bi
n
Culture_Nam
e
History_Dat
e
History_I
D
Category_Nam
e
ModifiedDate_Catg
o
SubCatgo_I
D
Prod_CatgoI
D
865 Classic Vest,
M
Blue M Light-weight, wind-
resistant, packs to fit into
a pocket.
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 English 2013-05-09
21:06:18.654
1 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬
‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬ ،‫ح‬ ٌ‫هر‬ ‫ن‬
.‫ٍة‬ ‫ج‬ ‫ان‬
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Arabic 2013-05-09
21:06:18.655
2 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M Sacs légers et résistants au
vent ; tiennent dans la
poche.
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 French 2013-05-09
21:06:18.655
3 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Thai 2013-05-09
21:06:18.655
4 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M ‫-קל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬
.‫לכיס‬ ‫המתאים‬ ‫לגודל‬
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Hebrew 2013-05-09
21:06:18.655
5 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M 轻型抗风,可折叠放入
口袋。
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Chinese 2013-05-09
21:06:18.656
6 Clothing 1998-06-01
00:00:00.000
25 3
Triggers
CREATE OR REPLACE TRIGGER T_Reports
BEFORE INSERT ON Territory_ReportS
REFERENCING NEW AS N
FOR EACH ROW
BEGIN
SET self_recursion OFF;
CASE WHEN N.CountryRegionCode ='GB'
THEN
INSERT 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 CASE
END
CREATE OR REPLACE TRIGGER TERRITORYRPT_GB
AFTER INSERT ON Territory_ReportGB
REFERENCING NEW AS N
FOR EACH ROW
BEGIN
SET 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,
21
N.ProductSubcategoryID, N.CategoryName, N.ProductCategoryID, N.TerritoryName,
N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID,
N.REPORT_DATE);
END
XML
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PD.ProductID = 713
FOR XML AUTO
forxml(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 seconds
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PD.ProductID = 713
FOR XML RAW
forxml(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 seconds
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
22
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PD.ProductID = 713
FOR XML RAW, ELEMENTS
forxml(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 seconds
SELECT ProductID, xmlelement(NAME DESCRIPTION,
xmlforest(
PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name
) ) AS Prod_Info
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PD.ProductID = 713
FOR XML RAW, ELEMENTS
forxml(1,'ProductID',xmltab."1",'Prod_Info',xmltab."2")
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<row ProductID="713" Prod_Info="&lt;DESCRIPTION&gt;&lt;ProductID&gt;713&lt;/ProductID&gt;&lt;NAME&gt;Long-Sleeve Logo Jersey,
S&lt;/NAME&gt;&lt;COLOR&gt;Multi&lt;/COLOR&gt;&lt;Size&gt;S&lt;/Size&gt;&lt;SubCatgo_Name&gt;Jerseys&lt;/SubCatgo_Name&gt;&lt;/DES
(1 rows)
Execution time: 0.029 seconds
SELECT ProductID, xmlelement(NAME DESCRIPTION,
xmlforest(
PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name
) ) AS Prod_Info
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PD.ProductID = 713
ProductID 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 seconds
Cursors
CREATE VIEW EMOINFO
AS
SELECT 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 AGE
FROM HumanResources.Employee HRE
23
INNER JOIN PERSON.Person PER
ON
HRE.BusinessEntityID = PER.BusinessEntityID
BEGIN
DECLARE @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 FOR
SELECT BusinessEntityID,FirstName||','|| MiddleName||','||LastName as Emp_Name,
BirthDate, Gender, MaritalStatus, NationalIDNumber,
SickLeaveHours, VacationHours,AGE
FROM EMOINFO
where BusinessEntityID = 19;
OPEN @EMPRED;
fetch next @EMPRED
into @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 45
Execution time: 0.047 seconds
24
DBA
Copying data from Sybase SQL AnyWhere AdventureWorks Database to Sybase SQL AnyWhere Rock Database using Sybase Central
25
26
SELECT * FROM "SUNNY"."PRODHISTORY"
Product_I
D
Product_Na
me
Product_Col
or
Product_Si
ze
SizeUnitMeasureC
ode
Product_Description SubCatgo_Na
me
Quantit
y
Shel
f
LocationI
D
ModifiedDate_SubCa
tgo
P_Bi
n
Culture_Na
me
History_Da
te
History_I
D
Category_Na
me
ModifiedDate_Cat
go
SubCatgo_I
D
Prod_CatgoI
D
865 Classic Vest,
M
Blue M Light-weight, wind-resistant, packs to
fit into a pocket.
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 English 2013-05-09
21:06:18.65
4
1 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M ،‫ح‬ ٌ‫هر‬ ‫ن‬ ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬
.‫ٍة‬ ‫ج‬ ‫ان‬ ‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Arabic 2013-05-09
21:06:18.65
5
2 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M Sacs légers et résistants au vent ;
tiennent dans la poche.
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 French 2013-05-09
21:06:18.65
5
3 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Thai 2013-05-09
21:06:18.65
5
4 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M ‫-קל‬ ‫המתאים‬ ‫לגודל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬
.‫לכיס‬
Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Hebrew 2013-05-09
21:06:18.65
5
5 Clothing 1998-06-01
00:00:00.000
25 3
865 Classic Vest,
M
Blue M 轻型抗风,可折叠放入口袋。 Vests 216 N/A 7 2003-06-01
00:00:00.000
0 Chinese 2013-05-09
21:06:18.65
6
6 Clothing 1998-06-01
00:00:00.000
25 3
select * from sysprocedure where PROC_NAME ='ProdHistory' OR
PROC_NAME ='PRODUCTS'
OR
PROC_NAME ='PRODUCTS2'
OR
PROC_NAME ='SALES_TERRITORY_GB'
OR
PROC_NAME = 'SalesTerritory_Report'
proc
_id
crea
tor
objec
t_id
proc_name proc_defn rema
rks
repli
cate
srv
id
source avg_num
_rows
avg_
cost
stats
353 1 4728 ProdHistory create procedure DBA.ProdHistory(
in @ProductID integer )
begin
if @ProductID is not null then
insert 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,
ProductCategoryID
from PRODUCTH
where ProductID = @ProductID
end if
end
N create PROCEDURE DBA."ProdHistory"(
in @ProductID INTEGER
)
BEGIN
IF @ProductID IS NOT NULL
THEN
INSERT 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,
ProductCategoryID
FROM PRODUCTH
WHERE ProductID = @ProductID ;
END IF ;
End
Bin
ary
Dat
a
347 1 4384 PRODUCTS create procedure DBA.PRODUCTS
as
select PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode,
PPD.Description,SubCatgo_Name=PSC.Name
from Production.ProductDescription as PPD
join Production.ProductModelProductDescriptionCulture as PMPDC
on PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
join Production.ProductModel as PM
on PMPDC.ProductModelID = PM.ProductModelID
join PRODUCTION.Product as PD
on PD.ProductModelID = PM.ProductModelID
join PRODUCTION.Culture as CUL
on PMPDC.CultureID = CUL.CultureID
join PRODUCTION.ProductSubcategory as PSC
on PSC.ProductSubcategoryID = PD.ProductSubcategoryID
where CUL.NAME = 'ENGLISH'
N create PROCEDURE PRODUCTS()
AS
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,
PPD.Description,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
Bin
ary
Dat
a
27
WHERE CUL.NAME = 'ENGLISH'
348 1 4385 PRODUCTS2 create procedure DBA.PRODUCTS2(
@sub_catgo_name char(35) )
as
select PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode,
PPD.Description,SubCatgo_Name=PSC.Name
from Production.ProductDescription as PPD
join Production.ProductModelProductDescriptionCulture as PMPDC
on PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
join Production.ProductModel as PM
on PMPDC.ProductModelID = PM.ProductModelID
join PRODUCTION.Product as PD
on PD.ProductModelID = PM.ProductModelID
join PRODUCTION.Culture as CUL
on PMPDC.CultureID = CUL.CultureID
join PRODUCTION.ProductSubcategory as PSC
on PSC.ProductSubcategoryID = PD.ProductSubcategoryID
where CUL.NAME = 'ENGLISH'
and PSC.NAME = @sub_catgo_name
N create PROCEDURE PRODUCTS2
(@sub_catgo_name char(35)
)
AS
SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,
PPD.Description,PSC.Name AS SubCatgo_Name
FROM Production.ProductDescription PPD
Inner join Production. ProductModelProductDescriptionCulture PMPDC
ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID
Inner Join
Production.ProductModel PM
ON
PMPDC.ProductModelID = PM.ProductModelID
INNER JOIN
PRODUCTION.Product PD
ON
PD.ProductModelID = PM.ProductModelID
INNER JOIN PRODUCTION.Culture CUL
ON
PMPDC.CultureID = CUL.CultureID
INNER JOIN
PRODUCTION.ProductSubcategory PSC
ON
PSC.ProductSubcategoryID = PD.ProductSubcategoryID
WHERE CUL.NAME = 'ENGLISH'
AND PSC.NAME = @sub_catgo_name
Bin
ary
Dat
a
352 1 4659 SALES_TERRIT
ORY_GB
create 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--
begin
case when @COUNTRYCODE = 'GB' then
select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,
CustomerID,SubTotal,TaxAmt,Freight,TotalDue,
PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,Product
CategoryID,
TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID
from SalesReports
where CountryRegionCode = @COUNTRYCODE
end case
end
N 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--
begin
CASE WHEN @COUNTRYCODE = 'GB'
THEN
select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID,
CustomerID,SubTotal,TaxAmt,Freight,TotalDue,
PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,Product
SubcategoryID,CategoryName,ProductCategoryID,
TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID
from SalesReports
where CountryRegionCode = @COUNTRYCODE
END CASE;
end
Bin
ary
Dat
a
346 1 4383 SalesTerritory_R
eport
create procedure DBA.SalesTerritory_Report(
@Region_Code char(8) )
as
select
SOH.SalesOrderNumber,OrderDate=convert(date,SOH.OrderDate),DueDate=convert(date,SOH.DueDate),ShipDate=convert(date,SO
H.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),S
OH.TOTALDUE),ProductName=PD.Name,TerritoryName=ST.NAME,
ST.CountryRegionCode,
TerritoryGroup=ST."Group",ST.TerritoryID
from Sales.SalesOrderDetail as SOD
join Sales.SalesOrderHeader as SOH
on SOD.SalesOrderID = SOH.SalesOrderID
join Production.Product as PD
on SOD.PRODUCTID = PD.PRODUCTID
join SALES.SalesTerritory as ST
on SOH.TerritoryID = ST.TerritoryID
where CountryRegionCode = @Region_Code
order by PD.NAME asc
N create PROCEDURE SalesTerritory_Report
(@Region_Code Char(8))
AS
SELECT 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.TerritoryID
FROM Sales.SalesOrderDetail SOD
INNER JOIN Sales.SalesOrderHeader SOH
ON
SOD.SalesOrderID = SOH.SalesOrderID
INNER JOIN Production.Product PD
ON SOD.PRODUCTID = PD.PRODUCTID
INNER JOIN
SALES.SalesTerritory ST
ON
SOH.TerritoryID = ST.TerritoryID
where CountryRegionCode = @Region_Code
ORDER BY PD.NAME
Bin
ary
Dat
a
28
select * from sysTRIGGERS
WHERE
TRIGNAME = 'TERRITORYRPT_GB' OR TRIGNAME ='T_Reports'
owner trigname tname event trigtime trigdefn
DBA T_Reports Territory_ReportS INSERT BEFORE create trigger T_Reports before insert on
DBA.Territory_ReportS
referencing new as N
for each row
begin
set self_recursion off;
case when N.CountryRegionCode = 'GB' then
insert 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 case
end
DBA TERRITORYRPT_GB Territory_ReportGB INSERT AFTER create trigger TERRITORYRPT_GB after insert on
DBA.Territory_ReportGB
referencing new as N
for each row
begin
set 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 )
end
select * from sysprocedure where PROC_NAME ='ProdHistory' OR
PROC_NAME ='eMPaGE'
proc_id creator object_id proc_name proc_defn remarks replicate srvid source avg_num_rows avg_cost stats
351 1 4388 EMPAGE create function DBA.EMPAGE( in @SNN integer )
returns integer
begin
declare @EMPAGE1 integer;
select DATEDIFF(yy,HRE.BirthDate,current timestamp) as EAGE
into @EMPAGE1 from HumanResources.Employee as HRE
where HRE.NationalIDNumber = @SNN;
return(@EMPAGE1)
end
N create FUNCTION EMPAGE( in @SNN integer)
RETURNS INTEGER
BEGIN
DECLARE @EMPAGE1 integer;
SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE
INTO
@EMPAGE1
FROM HumanResources.Employee HRE
WHERE HRE.NationalIDNumber = @SNN;
RETURN (@EMPAGE1);
END
Binary Data
Remote Server
29
CREATE 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.
30
SELECT * FROM "DBA"."customer"
customer_id store_id first_name last_name email address_id active create_date last_update
1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
4 2 BARBARA JONES BARBARA.JONES@sakilacustomer.org 8 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
5 1 ELIZABETH BROWN ELIZABETH.BROWN@sakilacustomer.org 9 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
6 2 JENNIFER DAVIS JENNIFER.DAVIS@sakilacustomer.org 10 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
7 1 MARIA MILLER MARIA.MILLER@sakilacustomer.org 11 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000
8 2 SUSAN WILSON SUSAN.WILSON@sakilacustomer.org 12 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000

More Related Content

What's hot

BI Apps ETL 4- Informatica PowerCenter Express
BI  Apps ETL 4- Informatica PowerCenter  ExpressBI  Apps ETL 4- Informatica PowerCenter  Express
BI Apps ETL 4- Informatica PowerCenter ExpressSunny U Okoro
 
SQL Server and SSAS
SQL Server and SSAS SQL Server and SSAS
SQL Server and SSAS Sunny U Okoro
 
Getting started with odi
Getting started with odiGetting started with odi
Getting started with odichecksekhar
 
pdf of R for Cloud Computing
pdf of R for Cloud Computing pdf of R for Cloud Computing
pdf of R for Cloud Computing Ajay Ohri
 
Oracle11g arch
Oracle11g archOracle11g arch
Oracle11g archSal Marcus
 
Sql account-user-manual
Sql account-user-manualSql account-user-manual
Sql account-user-manualgeniusppang
 
Big data technologies : A survey
Big data technologies : A survey Big data technologies : A survey
Big data technologies : A survey fatimabenjelloun1
 
Firewall and proxy servers howto
Firewall and proxy servers howtoFirewall and proxy servers howto
Firewall and proxy servers howtoKumar
 
Fundamentals of Database Systems Laboratory Manual
Fundamentals of Database Systems Laboratory ManualFundamentals of Database Systems Laboratory Manual
Fundamentals of Database Systems Laboratory ManualSurafiel Habib
 
BI Apps Reports 4 Cognos BI and Crystal Reports
BI Apps Reports 4  Cognos BI and Crystal ReportsBI Apps Reports 4  Cognos BI and Crystal Reports
BI Apps Reports 4 Cognos BI and Crystal ReportsSunny U Okoro
 
Getting Started with OpenStack and VMware vSphere
Getting Started with OpenStack and VMware vSphereGetting Started with OpenStack and VMware vSphere
Getting Started with OpenStack and VMware vSphereEMC
 
Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4samsherwood
 
Business Analysis Project 2015
Business Analysis Project 2015Business Analysis Project 2015
Business Analysis Project 2015Sam Gritzmacher
 
Pandora FMS: Open LDAP server monitoring administrator's manual
Pandora FMS: Open LDAP server monitoring administrator's manualPandora FMS: Open LDAP server monitoring administrator's manual
Pandora FMS: Open LDAP server monitoring administrator's manualPandora FMS
 

What's hot (20)

Database Migration
Database MigrationDatabase Migration
Database Migration
 
BI Apps ETL 4- Informatica PowerCenter Express
BI  Apps ETL 4- Informatica PowerCenter  ExpressBI  Apps ETL 4- Informatica PowerCenter  Express
BI Apps ETL 4- Informatica PowerCenter Express
 
SQL Server and SSAS
SQL Server and SSAS SQL Server and SSAS
SQL Server and SSAS
 
Getting started with odi
Getting started with odiGetting started with odi
Getting started with odi
 
Oracle ODI
Oracle ODIOracle ODI
Oracle ODI
 
pdf of R for Cloud Computing
pdf of R for Cloud Computing pdf of R for Cloud Computing
pdf of R for Cloud Computing
 
Knowledge base
Knowledge baseKnowledge base
Knowledge base
 
Oracle11g arch
Oracle11g archOracle11g arch
Oracle11g arch
 
Sql account-user-manual
Sql account-user-manualSql account-user-manual
Sql account-user-manual
 
Big data technologies : A survey
Big data technologies : A survey Big data technologies : A survey
Big data technologies : A survey
 
Firewall and proxy servers howto
Firewall and proxy servers howtoFirewall and proxy servers howto
Firewall and proxy servers howto
 
Fundamentals of Database Systems Laboratory Manual
Fundamentals of Database Systems Laboratory ManualFundamentals of Database Systems Laboratory Manual
Fundamentals of Database Systems Laboratory Manual
 
1 Rac
1 Rac1 Rac
1 Rac
 
BI Apps Reports 4 Cognos BI and Crystal Reports
BI Apps Reports 4  Cognos BI and Crystal ReportsBI Apps Reports 4  Cognos BI and Crystal Reports
BI Apps Reports 4 Cognos BI and Crystal Reports
 
Getting Started with OpenStack and VMware vSphere
Getting Started with OpenStack and VMware vSphereGetting Started with OpenStack and VMware vSphere
Getting Started with OpenStack and VMware vSphere
 
MySQL Query Browser
MySQL Query BrowserMySQL Query Browser
MySQL Query Browser
 
Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4
 
Easywpseo 1.5-user-guide
Easywpseo 1.5-user-guideEasywpseo 1.5-user-guide
Easywpseo 1.5-user-guide
 
Business Analysis Project 2015
Business Analysis Project 2015Business Analysis Project 2015
Business Analysis Project 2015
 
Pandora FMS: Open LDAP server monitoring administrator's manual
Pandora FMS: Open LDAP server monitoring administrator's manualPandora FMS: Open LDAP server monitoring administrator's manual
Pandora FMS: Open LDAP server monitoring administrator's manual
 

Viewers also liked

NSE AND HOW IT’S INDICES ARE CALCULATED
NSE AND HOW IT’S INDICES ARE CALCULATEDNSE AND HOW IT’S INDICES ARE CALCULATED
NSE AND HOW IT’S INDICES ARE CALCULATEDFahad Aapu
 
1ο μέρος
1ο μέρος1ο μέρος
1ο μέροςgeorgiaba
 
The myths of exploratory testing
The myths of exploratory testingThe myths of exploratory testing
The myths of exploratory testingGlobe Testing
 
Art portfolio
Art portfolioArt portfolio
Art portfolioGorislav
 
Valenzuela, Eduardo. Nuevas Generaciones
Valenzuela, Eduardo. Nuevas GeneracionesValenzuela, Eduardo. Nuevas Generaciones
Valenzuela, Eduardo. Nuevas GeneracionesCristian Arce
 
Consumers Italy presentation
Consumers Italy presentationConsumers Italy presentation
Consumers Italy presentationconsumerenergy
 
الاختبار
الاختبارالاختبار
الاختبارMai Khaled
 
IS THE MARKETING INDUSTRY FCUKED
IS THE MARKETING INDUSTRY FCUKEDIS THE MARKETING INDUSTRY FCUKED
IS THE MARKETING INDUSTRY FCUKEDGeoff Glendenning
 
Kuliah 9 menulis proposal
Kuliah 9 menulis proposalKuliah 9 menulis proposal
Kuliah 9 menulis proposalAgus Dollar
 
Target Audience Analyse PR
Target Audience Analyse PRTarget Audience Analyse PR
Target Audience Analyse PRnctcmedia12
 
Mini Neons 2013
Mini Neons 2013 Mini Neons 2013
Mini Neons 2013 mini_neons
 
Wiki πρότυπο παρουσίασης
Wiki πρότυπο παρουσίασης Wiki πρότυπο παρουσίασης
Wiki πρότυπο παρουσίασης aivanoulis
 
Aerosol indigo dyeing
Aerosol indigo dyeingAerosol indigo dyeing
Aerosol indigo dyeingrafiq.liton
 

Viewers also liked (20)

NSE AND HOW IT’S INDICES ARE CALCULATED
NSE AND HOW IT’S INDICES ARE CALCULATEDNSE AND HOW IT’S INDICES ARE CALCULATED
NSE AND HOW IT’S INDICES ARE CALCULATED
 
1ο μέρος
1ο μέρος1ο μέρος
1ο μέρος
 
The myths of exploratory testing
The myths of exploratory testingThe myths of exploratory testing
The myths of exploratory testing
 
Art portfolio
Art portfolioArt portfolio
Art portfolio
 
Marketing digital
Marketing digitalMarketing digital
Marketing digital
 
presentation
presentationpresentation
presentation
 
Valenzuela, Eduardo. Nuevas Generaciones
Valenzuela, Eduardo. Nuevas GeneracionesValenzuela, Eduardo. Nuevas Generaciones
Valenzuela, Eduardo. Nuevas Generaciones
 
Consumers Italy presentation
Consumers Italy presentationConsumers Italy presentation
Consumers Italy presentation
 
الاختبار
الاختبارالاختبار
الاختبار
 
IS THE MARKETING INDUSTRY FCUKED
IS THE MARKETING INDUSTRY FCUKEDIS THE MARKETING INDUSTRY FCUKED
IS THE MARKETING INDUSTRY FCUKED
 
Viterbi2
Viterbi2Viterbi2
Viterbi2
 
Kuliah 9 menulis proposal
Kuliah 9 menulis proposalKuliah 9 menulis proposal
Kuliah 9 menulis proposal
 
Target Audience Analyse PR
Target Audience Analyse PRTarget Audience Analyse PR
Target Audience Analyse PR
 
Mini Neons 2013
Mini Neons 2013 Mini Neons 2013
Mini Neons 2013
 
ADR mechanisms 2
ADR mechanisms 2ADR mechanisms 2
ADR mechanisms 2
 
Wiki πρότυπο παρουσίασης
Wiki πρότυπο παρουσίασης Wiki πρότυπο παρουσίασης
Wiki πρότυπο παρουσίασης
 
Landscapes
LandscapesLandscapes
Landscapes
 
Jadwal UAS 2014.1
Jadwal UAS 2014.1Jadwal UAS 2014.1
Jadwal UAS 2014.1
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Aerosol indigo dyeing
Aerosol indigo dyeingAerosol indigo dyeing
Aerosol indigo dyeing
 

Similar to Sybase SQL AnyWhere12

Maa wp sun_apps11i_db10g_r2-2
Maa wp sun_apps11i_db10g_r2-2Maa wp sun_apps11i_db10g_r2-2
Maa wp sun_apps11i_db10g_r2-2Sal Marcus
 
Dw guide 11 g r2
Dw guide 11 g r2Dw guide 11 g r2
Dw guide 11 g r2sgyazuddin
 
Informatica installation guide
Informatica installation guideInformatica installation guide
Informatica installation guidecbosepandian
 
Coherence developer's guide
Coherence developer's guideCoherence developer's guide
Coherence developer's guidewangdun119
 
Oracle 11g release 2
Oracle 11g release 2Oracle 11g release 2
Oracle 11g release 2Adel Saleh
 
SQL Server Analysis Services
SQL Server Analysis ServicesSQL Server Analysis Services
SQL Server Analysis ServicesAhmed Al Salih
 
Osb developer's guide
Osb developer's guideOsb developer's guide
Osb developer's guideHarish B
 
Oracle forms and resports
Oracle forms and resportsOracle forms and resports
Oracle forms and resportspawansharma1986
 
B28654oas10g best pracitice
B28654oas10g best praciticeB28654oas10g best pracitice
B28654oas10g best praciticeCaipei Chen
 
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...ambitlick
 
Apress - Advanced Transact-SQL for SQL Server 2000.pdf
Apress - Advanced Transact-SQL for SQL Server 2000.pdfApress - Advanced Transact-SQL for SQL Server 2000.pdf
Apress - Advanced Transact-SQL for SQL Server 2000.pdfAlexadiaz52
 
Cc admin
Cc adminCc admin
Cc adminVenk Re
 
Livre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référenceLivre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référenceMicrosoft France
 
Integrating SDN into the Data Center
Integrating SDN into the Data CenterIntegrating SDN into the Data Center
Integrating SDN into the Data CenterJuniper Networks
 
Deployment Guide for Business Productivity Online Standard Suite: Whitepaper
Deployment Guide for Business Productivity Online Standard Suite: WhitepaperDeployment Guide for Business Productivity Online Standard Suite: Whitepaper
Deployment Guide for Business Productivity Online Standard Suite: WhitepaperMicrosoft Private Cloud
 
Oracle pl-sql user's guide & reference
Oracle   pl-sql user's guide & referenceOracle   pl-sql user's guide & reference
Oracle pl-sql user's guide & referencedesitaria
 

Similar to Sybase SQL AnyWhere12 (20)

Maa wp sun_apps11i_db10g_r2-2
Maa wp sun_apps11i_db10g_r2-2Maa wp sun_apps11i_db10g_r2-2
Maa wp sun_apps11i_db10g_r2-2
 
Dw guide 11 g r2
Dw guide 11 g r2Dw guide 11 g r2
Dw guide 11 g r2
 
Informatica installation guide
Informatica installation guideInformatica installation guide
Informatica installation guide
 
Coherence developer's guide
Coherence developer's guideCoherence developer's guide
Coherence developer's guide
 
Oracle_9i_Database_Getting_started
Oracle_9i_Database_Getting_startedOracle_9i_Database_Getting_started
Oracle_9i_Database_Getting_started
 
Oracle 11g release 2
Oracle 11g release 2Oracle 11g release 2
Oracle 11g release 2
 
SQL Server Analysis Services
SQL Server Analysis ServicesSQL Server Analysis Services
SQL Server Analysis Services
 
Osb developer's guide
Osb developer's guideOsb developer's guide
Osb developer's guide
 
Oracle forms and resports
Oracle forms and resportsOracle forms and resports
Oracle forms and resports
 
Plsql
PlsqlPlsql
Plsql
 
Open acc.1.0
Open acc.1.0Open acc.1.0
Open acc.1.0
 
B28654oas10g best pracitice
B28654oas10g best praciticeB28654oas10g best pracitice
B28654oas10g best pracitice
 
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...
CloudAnalyst: A CloudSim-based Tool for Modelling and Analysis of Large Scale...
 
Apress - Advanced Transact-SQL for SQL Server 2000.pdf
Apress - Advanced Transact-SQL for SQL Server 2000.pdfApress - Advanced Transact-SQL for SQL Server 2000.pdf
Apress - Advanced Transact-SQL for SQL Server 2000.pdf
 
Cc admin
Cc adminCc admin
Cc admin
 
Livre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référenceLivre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référence
 
Integrating SDN into the Data Center
Integrating SDN into the Data CenterIntegrating SDN into the Data Center
Integrating SDN into the Data Center
 
Install
InstallInstall
Install
 
Deployment Guide for Business Productivity Online Standard Suite: Whitepaper
Deployment Guide for Business Productivity Online Standard Suite: WhitepaperDeployment Guide for Business Productivity Online Standard Suite: Whitepaper
Deployment Guide for Business Productivity Online Standard Suite: Whitepaper
 
Oracle pl-sql user's guide & reference
Oracle   pl-sql user's guide & referenceOracle   pl-sql user's guide & reference
Oracle pl-sql user's guide & reference
 

More from Sunny U Okoro

Tableau Reports and Oracle OBIEE
Tableau Reports and  Oracle OBIEETableau Reports and  Oracle OBIEE
Tableau Reports and Oracle OBIEESunny U Okoro
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server Sunny U Okoro
 
Advanced ETL2 Pentaho
Advanced ETL2  Pentaho Advanced ETL2  Pentaho
Advanced ETL2 Pentaho Sunny U Okoro
 
BI Apps Reports2- Oracle OBIEE & SAP Business Objects
BI Apps Reports2- Oracle OBIEE & SAP Business ObjectsBI Apps Reports2- Oracle OBIEE & SAP Business Objects
BI Apps Reports2- Oracle OBIEE & SAP Business ObjectsSunny U Okoro
 
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional
BI Apps  OLAP & Reports- SSAS 2012 Tabular & Multidimensional BI Apps  OLAP & Reports- SSAS 2012 Tabular & Multidimensional
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional Sunny U Okoro
 
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,FormsAdvanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,FormsSunny U Okoro
 
Advanced ETL MS SSIS 2012 & Talend
Advanced ETL  MS  SSIS 2012 & Talend Advanced ETL  MS  SSIS 2012 & Talend
Advanced ETL MS SSIS 2012 & Talend Sunny U Okoro
 
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & AduitsDB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & AduitsSunny U Okoro
 
DB Devlop- PostgreSQL 9.2.4 IQ 15.4
DB Devlop- PostgreSQL 9.2.4  IQ 15.4DB Devlop- PostgreSQL 9.2.4  IQ 15.4
DB Devlop- PostgreSQL 9.2.4 IQ 15.4Sunny U Okoro
 
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012BI Apps Reports-Cognos,Crystal Reports & SSRS 2012
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012Sunny U Okoro
 
BI Apps ETL-SSIS 2008 & 2012, Pentaho & Talend
BI Apps ETL-SSIS 2008 & 2012, Pentaho & TalendBI Apps ETL-SSIS 2008 & 2012, Pentaho & Talend
BI Apps ETL-SSIS 2008 & 2012, Pentaho & TalendSunny U Okoro
 
BI Apps Data Mining- SQL Server Analysis Services 2008
BI Apps Data Mining- SQL Server Analysis Services 2008BI Apps Data Mining- SQL Server Analysis Services 2008
BI Apps Data Mining- SQL Server Analysis Services 2008Sunny U Okoro
 
Relational / XML DB -SQL Server & Oracle Database
 Relational /  XML DB -SQL Server & Oracle Database Relational /  XML DB -SQL Server & Oracle Database
Relational / XML DB -SQL Server & Oracle DatabaseSunny U Okoro
 
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Sunny U Okoro
 
Web Application PHP and MySQL Database
Web Application PHP and MySQL DatabaseWeb Application PHP and MySQL Database
Web Application PHP and MySQL DatabaseSunny U Okoro
 

More from Sunny U Okoro (19)

Tableau Reports and Oracle OBIEE
Tableau Reports and  Oracle OBIEETableau Reports and  Oracle OBIEE
Tableau Reports and Oracle OBIEE
 
DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server DB 3 Sybase ASE 15 & MS SQL Server
DB 3 Sybase ASE 15 & MS SQL Server
 
MS SSAS 2012 & MDX
MS SSAS 2012  &  MDXMS SSAS 2012  &  MDX
MS SSAS 2012 & MDX
 
Advanced ETL2 Pentaho
Advanced ETL2  Pentaho Advanced ETL2  Pentaho
Advanced ETL2 Pentaho
 
BI Apps Reports2- Oracle OBIEE & SAP Business Objects
BI Apps Reports2- Oracle OBIEE & SAP Business ObjectsBI Apps Reports2- Oracle OBIEE & SAP Business Objects
BI Apps Reports2- Oracle OBIEE & SAP Business Objects
 
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional
BI Apps  OLAP & Reports- SSAS 2012 Tabular & Multidimensional BI Apps  OLAP & Reports- SSAS 2012 Tabular & Multidimensional
BI Apps OLAP & Reports- SSAS 2012 Tabular & Multidimensional
 
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,FormsAdvanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
Advanced SSRS 2012-SSAS,SSIS, XML, ASP.NET,Forms
 
Advanced ETL MS SSIS 2012 & Talend
Advanced ETL  MS  SSIS 2012 & Talend Advanced ETL  MS  SSIS 2012 & Talend
Advanced ETL MS SSIS 2012 & Talend
 
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & AduitsDB Security Oracle 11g-Application Context, Dynamic Views & Aduits
DB Security Oracle 11g-Application Context, Dynamic Views & Aduits
 
DB Devlop- PostgreSQL 9.2.4 IQ 15.4
DB Devlop- PostgreSQL 9.2.4  IQ 15.4DB Devlop- PostgreSQL 9.2.4  IQ 15.4
DB Devlop- PostgreSQL 9.2.4 IQ 15.4
 
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012BI Apps Reports-Cognos,Crystal Reports & SSRS 2012
BI Apps Reports-Cognos,Crystal Reports & SSRS 2012
 
BI Apps ETL-SSIS 2008 & 2012, Pentaho & Talend
BI Apps ETL-SSIS 2008 & 2012, Pentaho & TalendBI Apps ETL-SSIS 2008 & 2012, Pentaho & Talend
BI Apps ETL-SSIS 2008 & 2012, Pentaho & Talend
 
IBM DB2 10
IBM DB2 10IBM DB2 10
IBM DB2 10
 
BI Apps Data Mining- SQL Server Analysis Services 2008
BI Apps Data Mining- SQL Server Analysis Services 2008BI Apps Data Mining- SQL Server Analysis Services 2008
BI Apps Data Mining- SQL Server Analysis Services 2008
 
Oracle 11G- PLSQL
Oracle 11G- PLSQLOracle 11G- PLSQL
Oracle 11G- PLSQL
 
MYSQL 5.5
MYSQL 5.5MYSQL 5.5
MYSQL 5.5
 
Relational / XML DB -SQL Server & Oracle Database
 Relational /  XML DB -SQL Server & Oracle Database Relational /  XML DB -SQL Server & Oracle Database
Relational / XML DB -SQL Server & Oracle Database
 
Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2Microsoft SQL Server 2008 R2
Microsoft SQL Server 2008 R2
 
Web Application PHP and MySQL Database
Web Application PHP and MySQL DatabaseWeb Application PHP and MySQL Database
Web Application PHP and MySQL Database
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Sybase SQL AnyWhere12

  • 1. Sybase SQL AnyWhere 12 By Sunny Okoro
  • 2. 1 Contents Database Platform................................................................................................................................................................... 2 Applications............................................................................................................................................................................... 2 Database Diagram................................................................................................................................................................ 5 Functions..................................................................................................................................................................................... 7 User Defined Function.........................................................................................................................................................10 Stored Procedures.................................................................................................................................................................11 DDL..............................................................................................................................................................................................14 Triggers......................................................................................................................................................................................20 XML..............................................................................................................................................................................................21 Cursors.......................................................................................................................................................................................22 DBA..............................................................................................................................................................................................24
  • 3. 2 Database Platform Sybase SQLAnyWhere 12 Applications Sybase Central Sybase PowerDesigner
  • 4. 3 Microsoft Excel and Power Pivot Microsoft Visual Studio 2012
  • 6. 5 Database Diagram Captured from Sybase PowerDesigner 16
  • 7. 6 FK_Store_SalesPerson_SalesPersonID FK_Store_BusinessEntity_BusinessEntityID FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID FK_SpecialOfferProduct_Product_ProductID FK_ShoppingCartItem_Product_ProductID FK_SalesTerritoryHistory_SalesTerritory_TerritoryID FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID FK_SalesTerritory_CountryRegion_CountryRegionCode FK_SalesTaxRate_StateProvince_StateProvinceID FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID FK_SalesPerson_SalesTerritory_TerritoryID FK_SalesPerson_Employee_BusinessEntityID FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID FK_SalesOrderHeader_SalesTerritory_TerritoryID FK_SalesOrderHeader_ShipMethod_ShipMethodID FK_SalesOrderHeader_SalesPerson_SalesPersonID FK_SalesOrderHeader_Customer_CustomerID FK_SalesOrderHeader_CurrencyRate_CurrencyRateID FK_SalesOrderHeader_CreditCard_CreditCardID FK_SalesOrderHeader_Address_ShipToAddressID FK_SalesOrderHeader_Address_BillToAddressID FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID FK_PersonCreditCard_CreditCard_CreditCardID FK_PersonCreditCard_Person_BusinessEntityID FK_Customer_SalesTerritory_TerritoryID FK_Customer_Store_StoreID FK_Customer_Person_PersonID FK_CurrencyRate_Currency_ToCurrencyCode FK_CurrencyRate_Currency_FromCurrencyCode FK_CountryRegionCurrency_Currency_CurrencyCode FK_CountryRegionCurrency_CountryRegion_CountryRegionCode FK_Vendor_BusinessEntity_BusinessEntityID FK_PurchaseOrderHeader_ShipMethod_ShipMethodID FK_PurchaseOrderHeader_Vendor_VendorID FK_PurchaseOrderHeader_Employee_EmployeeID FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID FK_PurchaseOrderDetail_Product_ProductID FK_ProductVendor_Vendor_BusinessEntityID FK_ProductVendor_UnitMeasure_UnitMeasureCode FK_ProductVendor_Product_ProductID FK_WorkOrderRouting_WorkOrder_WorkOrderID FK_WorkOrderRouting_Location_LocationID FK_WorkOrder_ScrapReason_ScrapReasonID FK_WorkOrder_Product_ProductID FK_TransactionHistory_Product_ProductID FK_ProductSubcategory_ProductCategory_ProductCategoryID FK_ProductReview_Product_ProductID FK_ProductProductPhoto_ProductPhoto_ProductPhotoID FK_ProductProductPhoto_Product_ProductID FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID FK_ProductModelProductDescriptionCulture_Culture_CultureID FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID FK_ProductModelIllustration_Illustration_IllustrationID FK_ProductModelIllustration_ProductModel_ProductModelID FK_ProductListPriceHistory_Product_ProductID FK_ProductInventory_Product_ProductID FK_ProductInventory_Location_LocationID FK_ProductDocument_Document_DocumentNodeID FK_ProductDocument_Product_ProductID FK_ProductCostHistory_Product_ProductID FK_Product_ProductSubcategory_ProductSubcategoryID FK_Product_ProductModel_ProductModelID FK_Product_UnitMeasure_WeightUnitMeasureCode FK_Product_UnitMeasure_SizeUnitMeasureCode FK_Document_Employee_Owner FK_BillOfMaterials_UnitMeasure_UnitMeasureCode FK_BillOfMaterials_Product_ComponentID FK_BillOfMaterials_Product_ProductAssemblyID FK_StateProvince_SalesTerritory_TerritoryID FK_StateProvince_CountryRegion_CountryRegionCode FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID FK_PersonPhone_Person_BusinessEntityID FK_Person_BusinessEntity_BusinessEntityID FK_Password_Person_BusinessEntityID FK_EmailAddress_Person_BusinessEntityID FK_BusinessEntityContact_BusinessEntity_BusinessEntityID FK_BusinessEntityContact_ContactType_ContactTypeID FK_BusinessEntityContact_Person_PersonID FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID FK_BusinessEntityAddress_AddressType_AddressTypeID FK_BusinessEntityAddress_Address_AddressID FK_Address_StateProvince_StateProvinceID FK_JobCandidate_Employee_BusinessEntityID FK_EmployeePayHistory_Employee_BusinessEntityID FK_EmployeeDepartmentHistory_Shift_ShiftID FK_EmployeeDepartmentHistory_Employee_BusinessEntityID FK_EmployeeDepartmentHistory_Department_DepartmentID FK_Employee_Person_BusinessEntityID Document DocumentNodeID Title Owner FolderFlag FileName FileExtension Revision ChangeNumber Status DocumentSummary Document rowguid ModifiedDate integer nvarchar integer bit nvarchar nvarchar nchar integer tinyint nvarchar varbinary(32767) uniqueidentifier timestamp <pk> <fk> <ak> Culture CultureID Name ModifiedDate nchar nvarchar timestamp <pk> BillOfMaterials BillOfMaterialsID ProductAssemblyID ComponentID StartDate EndDate UnitMeasureCode BOMLevel PerAssemblyQty ModifiedDate integer integer integer timestamp timestamp nchar smallint decimal(8,2) timestamp <pk> <fk1> <fk2> <fk3> StateProvince StateProvinceID StateProvinceCode CountryRegionCode IsOnlyStateProvinceFlag Name TerritoryID rowguid ModifiedDate integer nchar nvarchar bit nvarchar integer uniqueidentifier timestamp <pk> <fk1> <fk2> PhoneNumberType PhoneNumberTypeID Name ModifiedDate integer nvarchar timestamp <pk> PersonPhone BusinessEntityID PhoneNumber PhoneNumberTypeID ModifiedDate integer nvarchar integer timestamp <pk,fk1> <pk> <pk,fk2> Person BusinessEntityID PersonType NameStyle Title FirstName MiddleName LastName Suffix EmailPromotion AdditionalContactInfo Demographics rowguid ModifiedDate integer nchar bit nvarchar nvarchar nvarchar nvarchar nvarchar integer xml xml uniqueidentifier timestamp <pk,fk> Password BusinessEntityID PasswordHash PasswordSalt rowguid ModifiedDate integer varchar(128) varchar(10) uniqueidentifier timestamp <pk,fk> EmailAddress BusinessEntityID EmailAddressID EmailAddress rowguid ModifiedDate integer integer nvarchar uniqueidentifier timestamp <pk,fk> <pk> CountryRegion CountryRegionCode Name ModifiedDate nvarchar nvarchar timestamp <pk> ContactType ContactTypeID Name ModifiedDate integer nvarchar timestamp <pk> BusinessEntityContact BusinessEntityID PersonID ContactTypeID rowguid ModifiedDate integer integer integer uniqueidentifier timestamp <pk,fk3> <pk,fk1> <pk,fk2> BusinessEntityAddress BusinessEntityID AddressID AddressTypeID rowguid ModifiedDate integer integer integer uniqueidentifier timestamp <pk,fk3> <pk,fk1> <pk,fk2> BusinessEntity BusinessEntityID rowguid ModifiedDate integer uniqueidentifier timestamp <pk> AddressType AddressTypeID Name rowguid ModifiedDate integer nvarchar uniqueidentifier timestamp <pk> Address AddressID AddressLine1 AddressLine2 City StateProvinceID PostalCode SpatialLocation rowguid ModifiedDate integer nvarchar nvarchar nvarchar integer nvarchar st_geometry(32767) uniqueidentifier timestamp <pk> <fk> Shift ShiftID Name StartTime EndTime ModifiedDate tinyint nvarchar time time timestamp <pk> JobCandidate JobCandidateID BusinessEntityID Resume ModifiedDate integer integer xml timestamp <pk> <fk> EmployeePayHistory BusinessEntityID RateChangeDate Rate PayFrequency ModifiedDate integer timestamp numeric(19,4) tinyint timestamp <pk,fk> <pk> EmployeeDepartmentHistory BusinessEntityID DepartmentID ShiftID StartDate EndDate ModifiedDate integer smallint tinyint date date timestamp <pk,fk2> <pk,fk1> <pk,fk3> <pk> Employee BusinessEntityID NationalIDNumber LoginID JobTitle BirthDate MaritalStatus Gender HireDate SalariedFlag VacationHours SickLeaveHours CurrentFlag rowguid ModifiedDate integer nvarchar nvarchar nvarchar date nchar nchar date bit smallint smallint bit uniqueidentifier timestamp <pk,fk> Department DepartmentID Name GroupName ModifiedDate smallint nvarchar nvarchar timestamp <pk> Illustration IllustrationID Diagram ModifiedDate integer xml timestamp <pk> Location LocationID Name CostRate Availability ModifiedDate smallint nvarchar numeric(10,4) decimal(8,2) timestamp <pk> Product ProductID ProductNumber MakeFlag FinishedGoodsFlag Name Color SafetyStockLevel ReorderPoint ListPrice Size SizeUnitMeasureCode StandardCost WeightUnitMeasureCode Weight DaysToManufacture ProductLine Class Style ProductSubcategoryID ProductModelID SellStartDate SellEndDate DiscontinuedDate rowguid ModifiedDate integer nvarchar bit bit nvarchar nvarchar smallint smallint numeric(19,4) nvarchar nchar numeric(19,4) nchar decimal(8,2) integer nchar nchar nchar integer integer timestamp timestamp timestamp uniqueidentifier timestamp <pk> <fk1> <fk2> <fk4> <fk3> ProductCategory ProductCategoryID Name rowguid ModifiedDate integer nvarchar uniqueidentifier timestamp <pk> ProductCostHistory ProductID StartDate EndDate StandardCost ModifiedDate integer timestamp timestamp numeric(19,4) timestamp <pk,fk> <pk> ProductDescription ProductDescriptionID Description rowguid ModifiedDate integer nvarchar uniqueidentifier timestamp <pk> ProductDocument ProductID DocumentNodeID ModifiedDate integer integer timestamp <pk,fk1> <pk,fk2> ProductInventory ProductID LocationID Shelf Bin Quantity rowguid ModifiedDate integer smallint nvarchar tinyint smallint uniqueidentifier timestamp <pk,fk2> <pk,fk1> ProductListPriceHistory ProductID StartDate EndDate ListPrice ModifiedDate integer timestamp timestamp numeric(19,4) timestamp <pk,fk> <pk> ProductModel ProductModelID Name CatalogDescription Instructions rowguid ModifiedDate integer nvarchar xml xml uniqueidentifier timestamp <pk> ProductModelIllustration ProductModelID IllustrationID ModifiedDate integer integer timestamp <pk,fk1> <pk,fk2> ProductModelProductDescriptionCulture ProductModelID ProductDescriptionID CultureID ModifiedDate integer integer nchar timestamp <pk,fk3> <pk,fk1> <pk,fk2> ProductPhoto ProductPhotoID ThumbNailPhoto ThumbnailPhotoFileName LargePhoto LargePhotoFileName ModifiedDate integer varbinary(32767) nvarchar varbinary(32767) nvarchar timestamp <pk> ProductProductPhoto ProductID ProductPhotoID Primary ModifiedDate integer integer bit timestamp <pk,fk1> <pk,fk2> ProductReview ProductReviewID ProductID ReviewerName ReviewDate EmailAddress Rating Comments ModifiedDate integer integer nvarchar timestamp nvarchar integer nvarchar timestamp <pk> <fk> ProductSubcategory ProductSubcategoryID ProductCategoryID Name rowguid ModifiedDate integer integer nvarchar uniqueidentifier timestamp <pk> <fk> ScrapReason ScrapReasonID Name ModifiedDate smallint nvarchar timestamp <pk> TransactionHistory TransactionID ProductID ReferenceOrderID ReferenceOrderLineID TransactionDate TransactionType Quantity ActualCost ModifiedDate integer integer integer integer timestamp nchar integer numeric(19,4) timestamp <pk> <fk> UnitMeasure UnitMeasureCode Name ModifiedDate nchar nvarchar timestamp <pk> WorkOrder WorkOrderID ProductID OrderQty StockedQty ScrappedQty StartDate EndDate DueDate ScrapReasonID ModifiedDate integer integer integer integer smallint timestamp timestamp timestamp smallint timestamp <pk> <fk1> <fk2> WorkOrderRouting WorkOrderID ProductID OperationSequence LocationID ScheduledStartDate ScheduledEndDate ActualStartDate ActualEndDate ActualResourceHrs PlannedCost ActualCost ModifiedDate integer integer smallint smallint timestamp timestamp timestamp timestamp decimal(9,4) numeric(19,4) numeric(19,4) timestamp <pk,fk2> <pk> <pk> <fk1> ProductVendor ProductID BusinessEntityID AverageLeadTime StandardPrice LastReceiptCost LastReceiptDate MinOrderQty MaxOrderQty OnOrderQty UnitMeasureCode ModifiedDate integer integer integer numeric(19,4) numeric(19,4) timestamp integer integer integer nchar timestamp <pk,fk1> <pk,fk3> <fk2> PurchaseOrderDetail PurchaseOrderID PurchaseOrderDetailID DueDate OrderQty ProductID UnitPrice LineTotal ReceivedQty RejectedQty StockedQty ModifiedDate integer integer timestamp smallint integer numeric(19,4) numeric(19,4) decimal(8,2) decimal(8,2) decimal timestamp <pk,fk2> <pk> <fk1> PurchaseOrderHeader PurchaseOrderID RevisionNumber Status EmployeeID VendorID ShipMethodID OrderDate ShipDate SubTotal TaxAmt Freight TotalDue ModifiedDate integer tinyint tinyint integer integer integer timestamp timestamp numeric(19,4) numeric(19,4) numeric(19,4) numeric(19,4) timestamp <pk> <fk1> <fk2> <fk3> ShipMethod ShipMethodID Name ShipBase ShipRate rowguid ModifiedDate integer nvarchar numeric(19,4) numeric(19,4) uniqueidentifier timestamp <pk> Vendor BusinessEntityID AccountNumber Name CreditRating PreferredVendorStatus ActiveFlag PurchasingWebServiceURL ModifiedDate integer nvarchar nvarchar tinyint bit bit nvarchar timestamp <pk,fk> CountryRegionCurrency CountryRegionCode CurrencyCode ModifiedDate nvarchar nchar timestamp <pk,fk1> <pk,fk2> CreditCard CreditCardID CardType CardNumber ExpMonth ExpYear ModifiedDate integer nvarchar nvarchar tinyint smallint timestamp <pk> Currency CurrencyCode Name ModifiedDate nchar nvarchar timestamp <pk> CurrencyRate CurrencyRateID CurrencyRateDate FromCurrencyCode ToCurrencyCode AverageRate EndOfDayRate ModifiedDate integer timestamp nchar nchar numeric(19,4) numeric(19,4) timestamp <pk> <fk1> <fk2> Customer CustomerID PersonID StoreID TerritoryID AccountNumber rowguid ModifiedDate integer integer integer integer varchar(10) uniqueidentifier timestamp <pk> <fk1> <fk2> <fk3> PersonCreditCard BusinessEntityID CreditCardID ModifiedDate integer integer timestamp <pk,fk1> <pk,fk2> SalesOrderDetail SalesOrderID SalesOrderDetailID CarrierTrackingNumber OrderQty ProductID SpecialOfferID UnitPrice UnitPriceDiscount LineTotal rowguid ModifiedDate integer integer nvarchar smallint integer integer numeric(19,4) numeric(19,4) numeric(19,4) uniqueidentifier timestamp <pk,fk1> <pk> <fk2> <fk2> SalesOrderHeader SalesOrderID RevisionNumber OrderDate DueDate ShipDate Status OnlineOrderFlag SalesOrderNumber ShipMethodID PurchaseOrderNumber AccountNumber CustomerID SalesPersonID TerritoryID BillToAddressID ShipToAddressID CreditCardID CreditCardApprovalCode CurrencyRateID SubTotal TaxAmt Freight TotalDue Comment rowguid ModifiedDate integer tinyint timestamp timestamp timestamp tinyint bit nvarchar integer nvarchar nvarchar integer integer integer integer integer integer varchar(15) integer numeric(19,4) numeric(19,4) numeric(19,4) numeric(19,4) nvarchar uniqueidentifier timestamp <pk> <fk7> <fk5> <fk6> <fk8> <fk1> <fk2> <fk3> <fk4> SalesOrderHeaderSalesReason SalesOrderID SalesReasonID ModifiedDate integer integer timestamp <pk,fk2> <pk,fk1> SalesPerson BusinessEntityID TerritoryID SalesQuota Bonus CommissionPct SalesYTD SalesLastYear rowguid ModifiedDate integer integer numeric(19,4) numeric(19,4) numeric(10,4) numeric(19,4) numeric(19,4) uniqueidentifier timestamp <pk,fk1> <fk2> SalesPersonQuotaHistory BusinessEntityID QuotaDate SalesQuota rowguid ModifiedDate integer timestamp numeric(19,4) uniqueidentifier timestamp <pk,fk> <pk> SalesReason SalesReasonID Name ReasonType ModifiedDate integer nvarchar nvarchar timestamp <pk> SalesTaxRate SalesTaxRateID StateProvinceID TaxType TaxRate Name rowguid ModifiedDate integer integer tinyint numeric(10,4) nvarchar uniqueidentifier timestamp <pk> <fk> SalesTerritory TerritoryID Name CountryRegionCode Group SalesYTD SalesLastYear CostYTD CostLastYear rowguid ModifiedDate integer nvarchar nvarchar nvarchar numeric(19,4) numeric(19,4) numeric(19,4) numeric(19,4) uniqueidentifier timestamp <pk> <fk> SalesTerritoryHistory BusinessEntityID TerritoryID StartDate EndDate rowguid ModifiedDate integer integer timestamp timestamp uniqueidentifier timestamp <pk,fk1> <pk,fk2> <pk> ShoppingCartItem ShoppingCartItemID ShoppingCartID Quantity ProductID DateCreated ModifiedDate integer nvarchar integer integer timestamp timestamp <pk> <fk> SpecialOffer SpecialOfferID Description DiscountPct Type Category StartDate EndDate MinQty MaxQty rowguid ModifiedDate integer nvarchar numeric(10,4) nvarchar nvarchar timestamp timestamp integer integer uniqueidentifier timestamp <pk> SpecialOfferProduct SpecialOfferID ProductID rowguid ModifiedDate integer integer uniqueidentifier timestamp <pk,fk2> <pk,fk1> Store BusinessEntityID Name SalesPersonID Demographics rowguid ModifiedDate integer nvarchar integer xml uniqueidentifier timestamp <pk,fk1> <fk2>
  • 8. 7 Functions SELECT 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 OrderDate FROM Sales.Customer c inner join Sales.SalesOrderHeader soh on c.CustomerID = soh.CustomerID inner join Sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID CreditCardID SubTotal Freight TaxAmt TotalDue OrderDate 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 16281 24643.9362 616.0984 1971.5149 27231.5495 07-01-2001 Results Abridged SELECT string(LastName, FirstName) AS Person_Name, lastName||','||firstName as Person_Name2 FROM Person.Person Person_Name Person_Name2 SánchezKen Sánchez,Ken DuffyTerri Duffy,Terri TamburelloRoberto Tamburello,Roberto WaltersRob Walters,Rob EricksonGail Erickson,Gail GoldbergJossef Goldberg,Jossef Results Abridged SELECT 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 OrderDate FROM Sales.Customer c inner join Sales.SalesOrderHeader soh on c.CustomerID = soh.CustomerID inner join Sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryID ShipMethodID SubTotal Freight TaxAmt TotalDue OrderDate 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29825 AW00029825 43659 2001-07-13 2001-07-08 SO43659 PO522145787 5 5 24643.9362 616.0984 1971.5149 27231.5495 2001-July-1-Sunday,3 29672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,3 29672 AW00029672 43660 2001-07-13 2001-07-08 SO43660 PO18850127500 5 5 1553.1035 38.8276 124.2483 1716.1794 2001-July-1-Sunday,3 29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3 29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3 29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3 29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3 29734 AW00029734 43661 2001-07-13 2001-07-08 SO43661 PO18473189620 6 5 39422.1198 985.5530 3153.7696 43561.4424 2001-July-1-Sunday,3 Results Abridged SELECT 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 OrderDate FROM Sales.Customer c inner join Sales.SalesOrderHeader soh
  • 9. 8 on c.CustomerID = soh.CustomerID inner join Sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID inner join Sales.SalesTerritory j on soh.TerritoryID = j.TerritoryID CustomerID AccountNumber SalesOrderID DueDate ShipDate SalesOrderNumber PurchaseOrderNumber TerritoryName ShipMethodID Subtotal Freight TaxAmt TotalDue2 TotalDue OrderDate 29614 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,3 29614 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,3 29614 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,3 29614 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,3 29614 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,3 29614 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,3 29614 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,3 29747 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,3 29566 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,3 29566 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,3 29566 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,3 29566 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,3 29890 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,3 29890 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,3 29890 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,3 Results Abridged SELECT string(LastName, FirstName) AS Person_Name, UPPER (lastName)||','|| LOWER(firstName) as Person_Name2 FROM Person.Person Person_Name Person_Name2 SánchezKen SÁNCHEZ,ken DuffyTerri DUFFY,terri TamburelloRoberto TAMBURELLO,roberto WaltersRob WALTERS,rob EricksonGail ERICKSON,gail GoldbergJossef GOLDBERG,jossef MillerDylan MILLER,dylan MargheimDiane MARGHEIM,diane MatthewGigi MATTHEW,gigi RaheemMichael RAHEEM,michael CraciumOvidiu CRACIUM,ovidiu D'HersThierry D'HERS,thierry GalvinJanice GALVIN,janice SullivanMichael SULLIVAN,michael SalavariaSharon SALAVARIA,sharon BradleyDavid BRADLEY,david BrownKevin BROWN,kevin WoodJohn WOOD,john DempseyMary DEMPSEY,mary BenshoofWanida BENSHOOF,wanida EminhizerTerry EMINHIZER,terry HarnpadoungsatayaSariya HARNPADOUNGSATAYA,sariya Results Abridged WITH ORDERS4(CUSTOMER_ID,TOTAL_DUE) AS(SELECT CUSTOMERID AS CUSTOMER_ID, TotalDue AS TOTAL_DUE FROM ORDERS) SELECT DISTINCT (CUSTOMER_ID)as CUSTOMER_ID, cast(TOTAL_DUE as decimal (23,2))as TOTAL_DUE FROM ORDERS4 WHERE TOTAL_DUE <> (SELECT cast (max(TotalDue)as decimal (23,2)) FROM ORDERS) CUSTOMER_ID TOTAL_DUE 29825 27231.55 29672 1716.18 29734 43561.44 29994 38331.96 29565 556.20 29898 32390.20 29580 19005.21 30052 6718.05 29974 8095.79 29614 47815.63 29747 974.02 29566 8115.68 29890 10784.99 Results Abridged SELECT HRE.BusinessEntityID, HRE.BirthDate, HRE.Gender, HRE.MaritalStatus, HRE.NationalIDNumber, HRE.SickLeaveHours, HRE.VacationHours, DATEDIFF(YY, BirthDate , CURRENT_TIMESTAMP) AS AGE
  • 10. 9 FROM HumanResources.Employee HRE BusinessEntityID BirthDate Gender MaritalStatus NationalIDNumber SickLeaveHours VacationHours AGE 1 1959-03-02 M S 295847284 69 99 54 2 1961-09-01 F S 245797967 20 1 52 3 1964-12-13 M M 509647174 21 2 49 4 1965-01-23 M S 112457891 80 48 48 5 1942-10-29 F M 695256908 22 5 71 6 1949-04-11 M M 998320692 23 6 64 7 1977-03-27 M M 134969118 50 61 36 8 1976-07-06 F S 811994146 51 62 37 9 1969-02-21 F M 658797903 51 63 44 10 1975-01-01 M M 879342154 64 16 38 11 1968-02-18 M S 974026903 23 7 45 12 1949-08-29 M M 480168528 24 9 64 13 1979-06-29 F M 486228782 24 8 34 14 1969-07-17 M S 42487730 21 3 44 15 1951-06-03 F M 56920285 22 4 62 16 1965-04-19 M S 24756624 40 40 48 17 1977-06-03 M S 253022876 41 42 36 Results Abridged SELECT 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 TerritoryGroup FROM Sales.SalesOrderHeader SOH INNER JOIN Sales.Customer SC ON SOH. CUSTOMERID = SC.CUSTOMERID INNER JOIN Sales.CreditCard SCC ON SCC.CREDITCARDID = SOH.CREDITCARDID INNER JOIN SALES.CurrencyRate SCR ON SOH.CurrencyRateID = SCR.CurrencyRateID INNER JOIN SALES.SalesTerritory STR ON STR.TerritoryID = SOH.TerritoryID INNER JOIN SALES.Currency SCY ON SCY.CurrencyCode = SCR.FromCurrencyCode OR SCY.CurrencyCode = SCR.ToCurrencyCode CustomerID OrderDate SalesOrderID Freight TaxAmt TotalDue CardType CardNum EXP_DATE Currency_Name CountryRegionCode Territory_Name TerritoryGroup 29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 US Dollar CA Canada North America 29734 2001-07-01 43661 985.55 3153.77 43561.44 Distinguish 0xefb7785a52c60cb9c9a3d3f0f28f3a3b3fd0867fa05bdb18db2f989ce78d0894 9-2007 Canadian Dollar CA Canada North America 29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 US Dollar CA Canada North America 29994 2001-07-01 43662 867.24 2775.16 38331.96 ColonialVoice 0x48dc87c0e811fa57175e155dd70fbf1955c087036917ff8264b9939a8c3e54d4 1-2006 Canadian Dollar CA Canada North America 29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 US Dollar CA Canada North America 29614 2001-07-01 43668 1081.80 3461.77 47815.63 ColonialVoice 0x35897b5ee7b21cf16e3a9a7960a4c153552917e14c6094338c808810207de212 11-2008 Canadian Dollar CA Canada North America 30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 US Dollar CA Canada North America 30067 2001-07-01 43672 183.63 587.60 8116.26 Vista 0x64a8d7a7dab2cecd5f6c22668b736db6bc47dd8bc6d1abc5d16c2e11ec58c4bd 3-2006 Canadian Dollar CA Canada North America 29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 US Dollar CA Canada North America 29596 2001-07-01 43674 78.73 251.94 3479.93 SuperiorCard 0x8219aaaac5c8bf1d0e92301fefb2f876244494067ff7c8357f29ce4cd2b9ced8 4-2005 Canadian Dollar CA Canada North America 29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 US Dollar CA Canada North America 29824 2001-07-01 43677 233.47 747.10 10319.33 SuperiorCard 0xae39eae197c2691c9a7b5e3356175a8f53f1d7bc5e6dbed1359c0ca358098495 4-2006 Canadian Dollar CA Canada North America 29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 US Dollar CA Canada North America 29761 2001-07-01 43679 39.31 125.80 1737.66 SuperiorCard 0x394b3d44f4e5b7fccbd26d6d4e3fba6d4121dcf0472f7a4ac9eb922222f9a020 9-2008 Canadian Dollar CA Canada North America 21768 2001-07-01 43697 89.46 286.26 3953.99 SuperiorCard 0x477e43dc99fc3fc8e8dc127b735cf3c51b37b17addfb8f0064d3e3c2fffc0d0e 7-2008 US Dollar CA Canada North America Results Abridged SELECT 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_Name FROM Sales.SalesOrderHeader SOH INNER JOIN SALES.SalesTerritory STR ON STR.TerritoryID = SOH.TerritoryID where STR.CountryRegionCode = 'US'
  • 11. 10 SalesOrderID CustomerID TotalDue CountryRegionCode Territory_Name TerritoryGroup TOTAL_Territor_Sales_Region TOTAL_Territor_Sales_Group TOTAL_Territor_Sales_Name 66560 21246 1320.44 US Southwest North America 82425339.37 82425339.37 31213458.71 70656 24831 2649.85 US Southwest North America 82425339.37 82425339.37 31213458.71 70912 17441 2657.47 US Southwest North America 82425339.37 82425339.37 31213458.71 44544 29522 27847.06 US Southwest North America 82425339.37 82425339.37 31213458.71 45568 29637 20205.63 US Southwest North America 82425339.37 82425339.37 31213458.71 46336 29944 556.20 US Southwest North America 82425339.37 82425339.37 31213458.71 47104 13279 2410.63 US Southwest North America 82425339.37 82425339.37 31213458.71 47360 29696 1051.23 US Southwest North America 82425339.37 82425339.37 31213458.71 48128 26534 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.71 48384 29562 90625.93 US Southwest North America 82425339.37 82425339.37 31213458.71 48640 26681 2288.92 US Southwest North America 82425339.37 82425339.37 31213458.71 49152 29792 30842.05 US Southwest North America 82425339.37 82425339.37 31213458.71 49408 15535 865.20 US Southwest North America 82425339.37 82425339.37 31213458.71 50688 29793 77584.01 US Southwest North America 82425339.37 82425339.37 31213458.71 51968 13171 132.60 US Southwest North America 82425339.37 82425339.37 31213458.71 55296 29850 2916.30 US Southwest North America 82425339.37 82425339.37 31213458.71 57344 12047 38.68 US Southwest North America 82425339.37 82425339.37 31213458.71 58368 25208 30.14 US Southwest North America 82425339.37 82425339.37 31213458.71 60160 13454 2590.41 US Southwest North America 82425339.37 82425339.37 31213458.71 Results Abridged User Defined Function CREATE OR REPLACE FUNCTION EMPAGE( ) RETURNS INTEGER BEGIN SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE FROM HumanResources.Employee HRE END; SELECT SELECT "DBA"."EMPAGE"(); CREATE OR REPLACE FUNCTION EMPAGE( in @SNN integer) RETURNS INTEGER BEGIN DECLARE @EMPAGE1 integer; SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE INTO @EMPAGE1 FROM HumanResources.Employee HRE WHERE HRE.NationalIDNumber = @SNN; RETURN (@EMPAGE1); END; SELECT "DBA"."EMPAGE"(509647174 ) AS EMP_AGE;
  • 12. 11 Stored Procedures CREATE OR REPLACE PROCEDURE SalesTerritory_Report (@Region_Code Char(8)) AS SELECT 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.TerritoryID FROM Sales.SalesOrderDetail SOD INNER JOIN Sales.SalesOrderHeader SOH ON SOD.SalesOrderID = SOH.SalesOrderID INNER JOIN Production.Product PD ON SOD.PRODUCTID = PD.PRODUCTID INNER JOIN SALES.SalesTerritory ST ON SOH.TerritoryID = ST.TerritoryID where CountryRegionCode = @Region_Code ORDER BY PD.NAME; EXEC SalesTerritory_Report('GB') SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID SO73803 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 SO70784 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 10 SO71313 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 10 SO74525 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 10 SO69201 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 10 SO69205 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 10 SO55484 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 10 SO60357 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 10 SO57657 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 10 SO64640 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 10 SO62727 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 10 SO56027 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 10 SO59644 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 10 SO57775 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 10 SO64183 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 10 Results Abridged CREATE OR REPLACE PROCEDURE PRODUCTS() AS SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode, PPD.Description,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD
  • 13. 12 Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' exec PRODUCTS; ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name 680 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 Frames 706 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 Frames 707 Sport-100 Helmet, Red Red Universal fit, well-vented, lightweight , snap-on visor. Helmets 708 Sport-100 Helmet, Black Black Universal fit, well-vented, lightweight , snap-on visor. Helmets 709 Mountain Bike Socks, M White M Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks 710 Mountain Bike Socks, L White L Combination of natural and synthetic fibers stays dry and provides just the right cushioning. Socks 711 Sport-100 Helmet, Blue Blue Universal fit, well-vented, lightweight , snap-on visor. Helmets 712 AWC Logo Cap Multi Traditional style with a flip-up brim; one-size fits all. Caps 713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 717 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 Frames 718 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 Frames 719 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 Frames 720 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 Frames 721 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 Frames Results Abridged CREATE OR REPLACE PROCEDURE PRODUCTS2 (@sub_catgo_name char(35) ) AS SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode, PPD.Description,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PSC.NAME = @sub_catgo_name; Exec PRODUCTS2( ‘Jerseys’); ProductID NAME COLOR Size SizeUnitMeasureCode Description SubCatgo_Name 713 Long-Sleeve Logo Jersey, S Multi S Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 714 Long-Sleeve Logo Jersey, M Multi M Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 715 Long-Sleeve Logo Jersey, L Multi L Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 716 Long-Sleeve Logo Jersey, XL Multi XL Unisex long-sleeve AWC logo microfiber cycling jersey Jerseys 881 Short-Sleeve Classic Jersey, S Yellow S Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys 882 Short-Sleeve Classic Jersey, M Yellow M Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys 883 Short-Sleeve Classic Jersey, L Yellow L Short sleeve classic breathable jersey with superior moisture control, front zipper, and 3 back pockets. Jerseys 884 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. 13 in @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-- begin CASE WHEN @COUNTRYCODE = 'GB' THEN select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID, CustomerID,SubTotal,TaxAmt,Freight,TotalDue, PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID from SalesReports where CountryRegionCode = @COUNTRYCODE END CASE; End EXEC SALES_TERRITORY_GB('US') Execution time: 0.064 seconds EXEC SALES_TERRITORY_GB('UK') SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID SO73803 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 SO70784 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 10 SO71313 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 10 SO74525 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 10 SO69201 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 10 SO69205 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 10 SO55484 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 10 SO60357 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 10 SO57657 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 10 Results Abridged CREATE 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-- begin CASE WHEN @COUNTRYCODE = 'GB' THEN select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID, CustomerID,SubTotal,TaxAmt,Freight,TotalDue, PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID from SalesReports where CountryRegionCode = @COUNTRYCODE END CASE; End SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID SO73803 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. 14 SO70784 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 10 SO71313 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 10 SO74525 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 10 SO69201 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 10 SO69205 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 10 SO55484 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 10 SO60357 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 10 SO57657 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 10 Results Abridged DDL CREATE VIEW ORDERS AS SELECT 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 OrderDate FROM Sales.Customer c inner join Sales.SalesOrderHeader soh on c.CustomerID = soh.CustomerID inner join Sales.SalesOrderDetail sod on soh.SalesOrderID = sod.SalesOrderID inner join Sales.SalesTerritory j on soh.TerritoryID = j.TerritoryID SELECT 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_DUE2 FROM ORDERS GROUP BY CustomerID CUSTOMER_ID AVG_TOTAL_DUE SUM_TOTAL MAX_TOTAL_DUE MIN_TOTAL_DUE 20818 1259.80 7558.83 3953.99 720.97 24921 1254.27 5017.08 1303.87 1105.48 12648 2596.35 20770.84 2699.01 2264.25 16727 2708.69 5417.37 2708.69 2708.69 29012 87.27 174.55 87.27 87.27 12655 2814.05 30954.56 3953.99 2673.06 20817 2275.34 4550.68 3953.99 596.69 24920 1219.70 3659.09 1276.81 1105.48 16726 8.04 16.09 8.04 8.04 29019 1890.64 5671.91 3953.99 858.96 20816 1257.95 7547.72 3953.99 718.75 12654 32.54 130.17 40.08 9.93 24927 211.35 845.41 211.35 211.35 29018 70.69 212.06 70.69 70.69 16725 15.45 30.90 15.45 15.45 29017 3953.99 3953.99 3953.99 3953.99 Results Abridged SELECT 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.TerritoryID INTO ORDERS_RECORD FROM Sales.SalesOrderDetail SOD INNER JOIN Sales.SalesOrderHeader SOH ON SOD.SalesOrderID = SOH.SalesOrderID INNER JOIN Production.Product PD ON SOD.PRODUCTID = PD.PRODUCTID INNER JOIN SALES.SalesTerritory ST ON SOH.TerritoryID = ST.TerritoryID ORDER BY ST.CountryRegionCode Note 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_RECORD SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID SO43701 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. 15 SO43703 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 9 SO43704 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 9 SO43705 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 9 SO43709 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 9 SO43710 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 9 SO43715 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 9 SO43716 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 9 SO43717 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 9 SO43724 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 9 SO43727 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 9 SO43731 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 9 SO43732 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 9 SO43735 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 9 SO43736 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 9 SO43740 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 9 SO43743 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 9 SO43744 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 9 SO43745 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 9 SO43746 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 9 Results Abridged select top(5) * from ORDERS_RECORD SalesOrderNumber OrderDate DueDate ShipDate ProductID CustomerID SubTotal TaxAmt Freight TotalDue ProductName TerritoryName CountryRegionCode TerritoryGroup TerritoryID SO43701 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 SO43703 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 9 SO43704 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 9 SO43705 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 9 SO43709 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 9 Results 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_ReportGB ADD CONSTRAINT TERRITRPORT_RPID_PK PRIMARY KEY(REPORT_ID); ALTER TABLE Territory_ReportGB add AccountNumber varchar(30); /* A stored procedure will call this view to populate the report table for GB customers*/ create view SalesReports AS SELECT 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.TerritoryID FROM Sales.SalesOrderDetail SOD INNER JOIN Sales.SalesOrderHeader SOH ON SOD.SalesOrderID = SOH.SalesOrderID INNER JOIN Production.Product PD ON SOD.PRODUCTID = PD.PRODUCTID
  • 17. 16 INNER JOIN SALES.SalesTerritory ST ON SOH.TerritoryID = ST.TerritoryID INNER JOIN Production.ProductModel PM ON PM.ProductModelID = PD.ProductModelID INNER JOIN Production. ProductModelProductDescriptionCulture PMPDC ON PM.ProductModelID = PMPDC.ProductModelID INNER JOIN Production.ProductDescription PPD ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID INNER JOIN SALES.Customer CU ON SOH.CustomerID = CU.CustomerID INNER JOIN PRODUCTION.ProductCategory PC ON PSC.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_ADUIT ADD CONSTRAINT REPORTAD_ADID_PK PRIMARY KEY(ADUIT_ID); ALTER TABLE REPORT_ADUIT add 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. 17 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 , 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, TerritoryID FROM SalesReports WHERE CountryRegionCode ='GB' select * from REPORT_ADUIT /*The null column has been removed to allow the report fit to the document*/ SalesOrderNu mber ORDERD ATE DUEDAT E SHIPDA TE PRODUC TID CUSTOME RID SUBTOT AL TAXA MT FREIG HT TOTALD UE PRODUCTN AME DESCRIPTION COL OR SubCatgoN ame ProductSubcateg oryID CategoryN ame ProductCateg oryID TerritoryN ame CountryRegion Code TerritoryGr oup Territor yID REPORT _ID ADUIT _ID ADUIT_D ATE REPORT_D ATE SO57240 11/1/200 3 11/13/2 003 11/8/20 03 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap 经典式样,带有翻边; 均码。 Multi Caps 19 Clothing 3 United Kingdom GB Europe 10 8 3 5/6/2013 0:02 5/6/2013 0:02 SO57240 11/1/200 3 11/13/2 003 11/8/20 03 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap Multi Caps 19 Clothing 3 United Kingdom GB Europe 10 9 4 5/6/2013 0:02 5/6/2013 0:02 Results 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, TerritoryID FROM SalesReports WHERE CountryRegionCode ='GB' 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,
  • 19. 18 CustomerID, SubTotal,TaxAmt, Freight, TotalDue, PRODUCTNAME, "Description","COLOR" ,"Size", SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID, CategoryName, ProductCategoryID, TerritoryName,CountryRegionCode , TerritoryGroup, TerritoryID FROM SalesReports WHERE CountryRegionCode ='US' select TOP(2) * from Territory_ReportGB; SalesOrder Number ORDER DATE DUED ATE SHIPD ATE PRODU CTID CUSTO MERID SUBT OTAL TAX AMT FREI GHT TOTA LDUE PRODUC TNAME DESCRIPTION COL OR SI ZE SizeUnitMea sureCode SubCatg oName ProductSubc ategoryID Category Name ProductCat egoryID Territor yName CountryReg ionCode Territory Group Territo ryID REPOR T_ID REPORT _DATE AccountN umber SO51411 2003-07- 15 2003- 07-27 2003- 07-22 712 11239 2353.95 188.3 2 58.85 2601.11 AWC Logo Cap 经典式样,带有 翻边;均码。 Multi Caps 19 Clothing 3 United Kingdom GB Europe 10 88 2013-05- 09 16:55:53.7 63 AW00011 239 SO51411 2003-07- 15 2003- 07-27 2003- 07-22 712 11239 2353.95 188.3 2 58.85 2601.11 AWC Logo Cap ‫עם‬ ‫מסורתי‬ ‫סגנון‬ ‫גודל‬ ;‫מתרוממת‬ ‫מצחייה‬ .‫לכולם‬ ‫מתאים‬ ‫אחד‬ Multi Caps 19 Clothing 3 United Kingdom GB Europe 10 89 2013-05- 09 16:55:53.7 64 AW00011 239 select * from Territory_ReportGB WHERE CountryRegionCode = 'US' SalesOrderNumber 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 AccountNumber ------------------------- ---------- ---------- ---------- ----------- ----------- ------------------------------------- ------------------------------------- ------------------------------------- ------------------------------------- -------------------------------------------------- ----------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- --------------- ------------------- -------------------------------------------------- -------------------- -------------------------------------------------- ------- ---------- -------------------------------------------------- ----------------- -------------------------------------------------- ----------- ----------- ----------------------- ------------------------------ (0 rows) Execution time: 0.208 seconds select TOP(5) * from Territory_ReportS WHERE CountryRegionCode ='GB’ SalesOrder Number ORDER DATE DUED ATE SHIPD ATE PRODU CTID CUSTO MERID SUBT OTAL TAX AMT FREI GHT TOTA LDUE PRODUC TNAME DESCRIPTION COL OR SI ZE SizeUnitMea sureCode SubCatg oName ProductSubc ategoryID Categor yName ProductCat egoryID Territor yName CountryReg ionCode Territory Group Territo ryID REPO RT_ID REPORT _DATE AccountN umber SO57240 2003-11- 01 2003- 11-13 2003- 11-08 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap 经典式样,带有翻边 ;均码。 Mult i Caps 19 Clothing 3 United Kingdom GB Europe 10 4 2013-05- 09 16:55:53.5 52 AW00011 238 SO57240 2003-11- 01 2003- 11-13 2003- 11-08 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap ‫מצחייה‬ ‫עם‬ ‫מסורתי‬ ‫סגנון‬ ‫מתאים‬ ‫אחד‬ ‫גודל‬ ;‫מתרוממת‬ .‫לכולם‬ Mult i Caps 19 Clothing 3 United Kingdom GB Europe 10 5 2013-05- 09 16:55:53.6 56 AW00011 238 SO57240 2003-11- 01 2003- 11-13 2003- 11-08 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap Mult i Caps 19 Clothing 3 United Kingdom GB Europe 10 6 2013-05- 09 16:55:53.6 57 AW00011 238 SO57240 2003-11- 01 2003- 11-13 2003- 11-08 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap Style classique avec une visière relevable ; taille unique. Mult i Caps 19 Clothing 3 United Kingdom GB Europe 10 7 2013-05- 09 16:55:53.6 60 AW00011 238 SO57240 2003-11- 01 2003- 11-13 2003- 11-08 712 11238 562.96 45.04 14.07 622.07 AWC Logo Cap ‫رو‬ ‫ٍذي‬ ‫ه‬ ‫ق‬ ‫ت‬ ‫مط‬ ‫و‬ ‫ح‬ ‫حاف‬ ،‫هى‬ ‫ألع‬ ‫الب‬‫ق‬ ‫الو‬ ‫ن‬ ‫هح‬ ‫ات‬ ‫ق‬ ‫م‬ ‫الئ‬ ٌ ‫واحذ‬ ‫حجم‬ ‫ت‬ .‫ٍع‬ ‫جم‬ ‫ان‬ Mult i Caps 19 Clothing 3 United Kingdom GB Europe 10 8 2013-05- 09 16:55:53.6 61 AW00011 238 select TOP(5) * from Territory_ReportS WHERE CountryRegionCode ='US' alesOrde rNumber ORDE RDAT E DUE DAT E SHIP DAT E PROD UCTI D CUSTO MERID SUBT OTAL TAX AMT FREI GHT TOTA LDUE PRODU CTNAM E DESCRIPTION CO LO R SI Z E SizeUnitMe asureCode SubCat goName ProductSub categoryID Catego ryNam e ProductC ategoryID Territo ryName CountryR egionCode Territor yGroup Territ oryID REPO RT_ID REPOR T_DAT E Account Number SO43670 2001- 07-01 2001- 07-13 2001- 07-08 773 29566 7344.5 0 587.5 6 183.6 1 8115.6 8 Mountain- 100 Silver, 44 HL Silv er 44 CM Mountai n Bikes 1 Bikes 1 Central US North America 3 62796 2013-05- 09 17:06:14. 134 AW0002 9566 SO43670 2001- 07-01 2001- 07-13 2001- 07-08 773 29566 7344.5 0 587.5 6 183.6 1 8115.6 8 Mountain- 100 Silver, 44 VTT de compétition haut de gamme. Plusieurs options d'amélioration des performances : cadre HL, suspension avant particulièrement souple et traction adaptée à tous les terrains. Silv er 44 CM Mountai n Bikes 1 Bikes 1 Central US North America 3 62797 2013-05- 09 17:06:14. 134 AW0002 9566 SO43670 2001- 07-01 2001- 07-13 2001- 07-08 773 29566 7344.5 0 587.5 6 183.6 1 8115.6 8 Mountain- 100 Silver, 44 ‫هى‬ ‫أع‬ ‫مه‬ ‫ثال‬ ‫ج‬ ‫ان‬ ً ‫ف‬ ‫ٍادج‬ ‫ق‬ ‫ه‬ ‫ن‬ ‫صح‬ ‫ص‬ ‫مخ‬ ‫اخ‬ ‫ثاق‬ ‫س‬ ‫دراجح‬ emarF LH ‫كم‬ ٍ ‫ه‬ ‫األداء‬ ‫ٍه‬ ‫س‬ ‫ح‬ ‫ت‬ ‫ٍاراخ‬ ‫خ‬ ‫ضمه‬ ‫ت‬ ‫ت‬ .‫طراز‬ ‫وج‬ ‫وق‬ ،‫قح‬ ‫فائ‬ ‫ان‬ ‫سح‬ ‫ال‬‫س‬ ‫ان‬ ‫ري‬ ً‫ام‬‫األم‬ ‫ٍق‬ ‫ه‬ ‫ع‬‫ت‬ ‫وان‬ ،ً‫ذاع‬ ‫اإلت‬ .ً‫ض‬ ‫األرا‬ ‫واع‬ ‫أو‬ ‫ٍع‬ ‫جم‬ ‫ن‬ ‫ثح‬ ‫س‬ ‫ىا‬ ‫م‬ ‫ان‬ ‫جر‬ ‫ان‬ Silv er 44 CM Mountai n Bikes 1 Bikes 1 Central US North America 3 62798 2013-05- 09 17:06:14. 134 AW0002 9566
  • 20. 19 SO43670 2001- 07-01 2001- 07-13 2001- 07-08 773 29566 7344.5 0 587.5 6 183.6 1 8115.6 8 Mountain- 100 Silver, 44 Top-of-the-line competition mountain bike. Performance-enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain. Silv er 44 CM Mountai n Bikes 1 Bikes 1 Central US North America 3 62799 2013-05- 09 17:06:14. 134 AW0002 9566 SO43670 2001- 07-01 2001- 07-13 2001- 07-08 776 29566 7344.5 0 587.5 6 183.6 1 8115.6 8 Mountain- 100 Black, 42 高档竞赛山地车。性能得到进一步增强,包括创 新的 HL 车架、极其平稳的前悬架以及适用于所有地形的 出色牵引力。 Blac k 42 CM Mountai n Bikes 1 CREATE or replace VIEW PRODUCTH AS SELECT 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_Catego FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID INNER JOIN PRODUCTION.ProductInventory PPI ON PD.ProductID = PPI.ProductID INNER JOIN PRODUCTION.ProductCategory PCI ON PSC.ProductCategoryID = PCI.ProductCategoryID CREATE 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 ) BEGIN IF @ProductID IS NOT NULL THEN INSERT 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. 20 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, ProductCategoryID FROM PRODUCTH WHERE ProductID = @ProductID ; END IF ; End SELECT * FROM PRODHISTORY Product_I D Product_Nam e Product_Colo r Product_Siz e SizeUnitMeasur eCode Product_Description SubCatgo_Nam e Quantit y Shel f LocationI D ModifiedDate_SubCatg o P_Bi n Culture_Nam e History_Dat e History_I D Category_Nam e ModifiedDate_Catg o SubCatgo_I D Prod_CatgoI D 865 Classic Vest, M Blue M Light-weight, wind- resistant, packs to fit into a pocket. Vests 216 N/A 7 2003-06-01 00:00:00.000 0 English 2013-05-09 21:06:18.654 1 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬ ‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬ ،‫ح‬ ٌ‫هر‬ ‫ن‬ .‫ٍة‬ ‫ج‬ ‫ان‬ Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Arabic 2013-05-09 21:06:18.655 2 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M Sacs légers et résistants au vent ; tiennent dans la poche. Vests 216 N/A 7 2003-06-01 00:00:00.000 0 French 2013-05-09 21:06:18.655 3 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Thai 2013-05-09 21:06:18.655 4 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M ‫-קל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬ .‫לכיס‬ ‫המתאים‬ ‫לגודל‬ Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Hebrew 2013-05-09 21:06:18.655 5 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M 轻型抗风,可折叠放入 口袋。 Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Chinese 2013-05-09 21:06:18.656 6 Clothing 1998-06-01 00:00:00.000 25 3 Triggers CREATE OR REPLACE TRIGGER T_Reports BEFORE INSERT ON Territory_ReportS REFERENCING NEW AS N FOR EACH ROW BEGIN SET self_recursion OFF; CASE WHEN N.CountryRegionCode ='GB' THEN INSERT 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 CASE END CREATE OR REPLACE TRIGGER TERRITORYRPT_GB AFTER INSERT ON Territory_ReportGB REFERENCING NEW AS N FOR EACH ROW BEGIN SET 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. 21 N.ProductSubcategoryID, N.CategoryName, N.ProductCategoryID, N.TerritoryName, N.CountryRegionCode,N.TerritoryGroup,N.TerritoryID,N.REPORT_ID, N.REPORT_DATE); END XML SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PD.ProductID = 713 FOR XML AUTO forxml(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 seconds SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PD.ProductID = 713 FOR XML RAW forxml(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 seconds SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC
  • 23. 22 ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PD.ProductID = 713 FOR XML RAW, ELEMENTS forxml(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 seconds SELECT ProductID, xmlelement(NAME DESCRIPTION, xmlforest( PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name ) ) AS Prod_Info FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PD.ProductID = 713 FOR XML RAW, ELEMENTS forxml(1,'ProductID',xmltab."1",'Prod_Info',xmltab."2") ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <row ProductID="713" Prod_Info="&lt;DESCRIPTION&gt;&lt;ProductID&gt;713&lt;/ProductID&gt;&lt;NAME&gt;Long-Sleeve Logo Jersey, S&lt;/NAME&gt;&lt;COLOR&gt;Multi&lt;/COLOR&gt;&lt;Size&gt;S&lt;/Size&gt;&lt;SubCatgo_Name&gt;Jerseys&lt;/SubCatgo_Name&gt;&lt;/DES (1 rows) Execution time: 0.029 seconds SELECT ProductID, xmlelement(NAME DESCRIPTION, xmlforest( PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode,PSC.Name AS SubCatgo_Name ) ) AS Prod_Info FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PD.ProductID = 713 ProductID 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 seconds Cursors CREATE VIEW EMOINFO AS SELECT 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 AGE FROM HumanResources.Employee HRE
  • 24. 23 INNER JOIN PERSON.Person PER ON HRE.BusinessEntityID = PER.BusinessEntityID BEGIN DECLARE @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 FOR SELECT BusinessEntityID,FirstName||','|| MiddleName||','||LastName as Emp_Name, BirthDate, Gender, MaritalStatus, NationalIDNumber, SickLeaveHours, VacationHours,AGE FROM EMOINFO where BusinessEntityID = 19; OPEN @EMPRED; fetch next @EMPRED into @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 45 Execution time: 0.047 seconds
  • 25. 24 DBA Copying data from Sybase SQL AnyWhere AdventureWorks Database to Sybase SQL AnyWhere Rock Database using Sybase Central
  • 26. 25
  • 27. 26 SELECT * FROM "SUNNY"."PRODHISTORY" Product_I D Product_Na me Product_Col or Product_Si ze SizeUnitMeasureC ode Product_Description SubCatgo_Na me Quantit y Shel f LocationI D ModifiedDate_SubCa tgo P_Bi n Culture_Na me History_Da te History_I D Category_Na me ModifiedDate_Cat go SubCatgo_I D Prod_CatgoI D 865 Classic Vest, M Blue M Light-weight, wind-resistant, packs to fit into a pocket. Vests 216 N/A 7 2003-06-01 00:00:00.000 0 English 2013-05-09 21:06:18.65 4 1 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M ،‫ح‬ ٌ‫هر‬ ‫ن‬ ‫قاومح‬ ‫وم‬ ،‫وزن‬ ‫ان‬ ‫فح‬ ٍ ‫ف‬ ‫خ‬ ‫هة‬ ‫ع‬ .‫ٍة‬ ‫ج‬ ‫ان‬ ‫حجم‬ ‫سة‬ ‫ىا‬ ‫ت‬ Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Arabic 2013-05-09 21:06:18.65 5 2 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M Sacs légers et résistants au vent ; tiennent dans la poche. Vests 216 N/A 7 2003-06-01 00:00:00.000 0 French 2013-05-09 21:06:18.65 5 3 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Thai 2013-05-09 21:06:18.65 5 4 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M ‫-קל‬ ‫המתאים‬ ‫לגודל‬ ‫מתקפל‬ ,‫מרוח‬ ‫מגן‬ ,‫משקל‬ .‫לכיס‬ Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Hebrew 2013-05-09 21:06:18.65 5 5 Clothing 1998-06-01 00:00:00.000 25 3 865 Classic Vest, M Blue M 轻型抗风,可折叠放入口袋。 Vests 216 N/A 7 2003-06-01 00:00:00.000 0 Chinese 2013-05-09 21:06:18.65 6 6 Clothing 1998-06-01 00:00:00.000 25 3 select * from sysprocedure where PROC_NAME ='ProdHistory' OR PROC_NAME ='PRODUCTS' OR PROC_NAME ='PRODUCTS2' OR PROC_NAME ='SALES_TERRITORY_GB' OR PROC_NAME = 'SalesTerritory_Report' proc _id crea tor objec t_id proc_name proc_defn rema rks repli cate srv id source avg_num _rows avg_ cost stats 353 1 4728 ProdHistory create procedure DBA.ProdHistory( in @ProductID integer ) begin if @ProductID is not null then insert 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, ProductCategoryID from PRODUCTH where ProductID = @ProductID end if end N create PROCEDURE DBA."ProdHistory"( in @ProductID INTEGER ) BEGIN IF @ProductID IS NOT NULL THEN INSERT 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, ProductCategoryID FROM PRODUCTH WHERE ProductID = @ProductID ; END IF ; End Bin ary Dat a 347 1 4384 PRODUCTS create procedure DBA.PRODUCTS as select PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode, PPD.Description,SubCatgo_Name=PSC.Name from Production.ProductDescription as PPD join Production.ProductModelProductDescriptionCulture as PMPDC on PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID join Production.ProductModel as PM on PMPDC.ProductModelID = PM.ProductModelID join PRODUCTION.Product as PD on PD.ProductModelID = PM.ProductModelID join PRODUCTION.Culture as CUL on PMPDC.CultureID = CUL.CultureID join PRODUCTION.ProductSubcategory as PSC on PSC.ProductSubcategoryID = PD.ProductSubcategoryID where CUL.NAME = 'ENGLISH' N create PROCEDURE PRODUCTS() AS SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode, PPD.Description,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID Bin ary Dat a
  • 28. 27 WHERE CUL.NAME = 'ENGLISH' 348 1 4385 PRODUCTS2 create procedure DBA.PRODUCTS2( @sub_catgo_name char(35) ) as select PD.ProductID,PD.NAME,PD.COLOR,PD.Size,PD.SizeUnitMeasureCode, PPD.Description,SubCatgo_Name=PSC.Name from Production.ProductDescription as PPD join Production.ProductModelProductDescriptionCulture as PMPDC on PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID join Production.ProductModel as PM on PMPDC.ProductModelID = PM.ProductModelID join PRODUCTION.Product as PD on PD.ProductModelID = PM.ProductModelID join PRODUCTION.Culture as CUL on PMPDC.CultureID = CUL.CultureID join PRODUCTION.ProductSubcategory as PSC on PSC.ProductSubcategoryID = PD.ProductSubcategoryID where CUL.NAME = 'ENGLISH' and PSC.NAME = @sub_catgo_name N create PROCEDURE PRODUCTS2 (@sub_catgo_name char(35) ) AS SELECT PD.ProductID, PD.NAME, PD.COLOR , PD.Size, PD.SizeUnitMeasureCode, PPD.Description,PSC.Name AS SubCatgo_Name FROM Production.ProductDescription PPD Inner join Production. ProductModelProductDescriptionCulture PMPDC ON PPD.PRODUCTDESCRIPTIONID = PMPDC.PRODUCTDESCRIPTIONID Inner Join Production.ProductModel PM ON PMPDC.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Product PD ON PD.ProductModelID = PM.ProductModelID INNER JOIN PRODUCTION.Culture CUL ON PMPDC.CultureID = CUL.CultureID INNER JOIN PRODUCTION.ProductSubcategory PSC ON PSC.ProductSubcategoryID = PD.ProductSubcategoryID WHERE CUL.NAME = 'ENGLISH' AND PSC.NAME = @sub_catgo_name Bin ary Dat a 352 1 4659 SALES_TERRIT ORY_GB create 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-- begin case when @COUNTRYCODE = 'GB' then select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID, CustomerID,SubTotal,TaxAmt,Freight,TotalDue, PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,ProductSubcategoryID,CategoryName,Product CategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID from SalesReports where CountryRegionCode = @COUNTRYCODE end case end N 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-- begin CASE WHEN @COUNTRYCODE = 'GB' THEN select SalesOrderNumber,AccountNumber,OrderDate,DueDate,ShipDate,ProductID, CustomerID,SubTotal,TaxAmt,Freight,TotalDue, PRODUCTNAME,Description,COLOR,Size,SizeUnitMeasureCode,SubCatgoName,Product SubcategoryID,CategoryName,ProductCategoryID, TerritoryName,CountryRegionCode,TerritoryGroup,TerritoryID from SalesReports where CountryRegionCode = @COUNTRYCODE END CASE; end Bin ary Dat a 346 1 4383 SalesTerritory_R eport create procedure DBA.SalesTerritory_Report( @Region_Code char(8) ) as select SOH.SalesOrderNumber,OrderDate=convert(date,SOH.OrderDate),DueDate=convert(date,SOH.DueDate),ShipDate=convert(date,SO H.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),S OH.TOTALDUE),ProductName=PD.Name,TerritoryName=ST.NAME, ST.CountryRegionCode, TerritoryGroup=ST."Group",ST.TerritoryID from Sales.SalesOrderDetail as SOD join Sales.SalesOrderHeader as SOH on SOD.SalesOrderID = SOH.SalesOrderID join Production.Product as PD on SOD.PRODUCTID = PD.PRODUCTID join SALES.SalesTerritory as ST on SOH.TerritoryID = ST.TerritoryID where CountryRegionCode = @Region_Code order by PD.NAME asc N create PROCEDURE SalesTerritory_Report (@Region_Code Char(8)) AS SELECT 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.TerritoryID FROM Sales.SalesOrderDetail SOD INNER JOIN Sales.SalesOrderHeader SOH ON SOD.SalesOrderID = SOH.SalesOrderID INNER JOIN Production.Product PD ON SOD.PRODUCTID = PD.PRODUCTID INNER JOIN SALES.SalesTerritory ST ON SOH.TerritoryID = ST.TerritoryID where CountryRegionCode = @Region_Code ORDER BY PD.NAME Bin ary Dat a
  • 29. 28 select * from sysTRIGGERS WHERE TRIGNAME = 'TERRITORYRPT_GB' OR TRIGNAME ='T_Reports' owner trigname tname event trigtime trigdefn DBA T_Reports Territory_ReportS INSERT BEFORE create trigger T_Reports before insert on DBA.Territory_ReportS referencing new as N for each row begin set self_recursion off; case when N.CountryRegionCode = 'GB' then insert 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 case end DBA TERRITORYRPT_GB Territory_ReportGB INSERT AFTER create trigger TERRITORYRPT_GB after insert on DBA.Territory_ReportGB referencing new as N for each row begin set 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 ) end select * from sysprocedure where PROC_NAME ='ProdHistory' OR PROC_NAME ='eMPaGE' proc_id creator object_id proc_name proc_defn remarks replicate srvid source avg_num_rows avg_cost stats 351 1 4388 EMPAGE create function DBA.EMPAGE( in @SNN integer ) returns integer begin declare @EMPAGE1 integer; select DATEDIFF(yy,HRE.BirthDate,current timestamp) as EAGE into @EMPAGE1 from HumanResources.Employee as HRE where HRE.NationalIDNumber = @SNN; return(@EMPAGE1) end N create FUNCTION EMPAGE( in @SNN integer) RETURNS INTEGER BEGIN DECLARE @EMPAGE1 integer; SELECT DATEDIFF(YY, HRE.BirthDate , CURRENT_TIMESTAMP) AS EAGE INTO @EMPAGE1 FROM HumanResources.Employee HRE WHERE HRE.NationalIDNumber = @SNN; RETURN (@EMPAGE1); END Binary Data Remote Server
  • 30. 29 CREATE 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. 30 SELECT * FROM "DBA"."customer" customer_id store_id first_name last_name email address_id active create_date last_update 1 1 MARY SMITH MARY.SMITH@sakilacustomer.org 5 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 2 1 PATRICIA JOHNSON PATRICIA.JOHNSON@sakilacustomer.org 6 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 3 1 LINDA WILLIAMS LINDA.WILLIAMS@sakilacustomer.org 7 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 4 2 BARBARA JONES BARBARA.JONES@sakilacustomer.org 8 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 5 1 ELIZABETH BROWN ELIZABETH.BROWN@sakilacustomer.org 9 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 6 2 JENNIFER DAVIS JENNIFER.DAVIS@sakilacustomer.org 10 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 7 1 MARIA MILLER MARIA.MILLER@sakilacustomer.org 11 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000 8 2 SUSAN WILSON SUSAN.WILSON@sakilacustomer.org 12 1 2006-02-14 22:04:36.000 2006-02-15 04:57:20.000