This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE SalesDB | |
GO | |
IF OBJECT_ID (N'dbo.LastPaymentFxn') IS NOT NULL | |
DROP FUNCTION dbo.LastPaymentFxn | |
GO | |
CREATE FUNCTION dbo.LastPaymentFxn | |
( | |
@CustomerID int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE pubs | |
GO | |
IF OBJECT_ID('dbo.AuthorIDXML', 'FN') IS NOT NULL | |
DROP FUNCTION dbo.AuthorIDXML | |
GO | |
CREATE FUNCTION dbo.AuthorIDXML | |
( | |
@AuID varchar(13) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- =================================================================== | |
/* ABOUT THIS SQL SERVER QUERY: Using XQuery can be a bit of a painful experience in SQL Server, in my opinion. What makes it more fun and manageable, however, is being able to use a CTE (common table expression) when querying your XML. In this example, we will query an XML document that contains day-by-day weather information for the city of Victoria, Canada over an entire year (except December). We are aiming to generate a result set that shows the total rainfall, minimum temperature, and maximum temperature that occurred in each calendar month of the year. In this case, using a CTE allows you to query an XML document and generate this desired relational result set (with aggregated data) pretty easily in SQL Server. */ | |
-- =================================================================== | |
-------------------------------------------------------------------- | |
/* IMPORTANT NOTE: In this example, I have declared a variable with the XML data |