Database Reference
In-Depth Information
Figure 13-8. Filtering results based on a given date
When you are working with filters, it is often necessary to add more flexibility in your queries by using tools
like the SQL wildcard searches. One classic example of a wildcard search is where you use the percentage sign
wildcard symbol (%) in conjunction with the SQL LIKE operator to indicate that zero or more missing characters
should be ignored for the purpose of a pattern match. In Listing 13-13 you can see an example of this where the
query asks SQL Server to find all the data where the letters PS are followed by zero or more number of characters.
Listing 13-13. Filtering Results Based on Title ID with a Wildcard Symbol
SELECT
DP.PublisherName
, [Title] = DT.TitleName
, [TitleId] = DT.TitleId
, [OrderDate] = CONVERT(varchar(50), [Date], 101)
, SalesQuantity
FROM DWPubsSales.dbo.FactSales AS FS
INNER JOIN DWPubsSales.dbo.DimTitles AS DT
ON FS.TitleKey = DT.TitleKey
INNER JOIN DWPubsSales.dbo.DimDates AS DD
ON FS.OrderDateKey = DD.DateKey
INNER JOIN DWPubsSales.dbo.DimPublishers AS DP
ON DT.PublisherKey = DP.PublisherKey
WHERE [TitleId] LIKE 'PS%' -- % means zero or more characters
ORDER BY DP.PublisherName, [Title], [OrderDate]
 
Search WWH ::




Custom Search