Database Reference
In-Depth Information
Figure 13-11. Results filtered by with the BETWEEN operator
Ti note that with the BETWEEN operator the results are inclusive. This is not always true of all SQL operators,
so whenever you use an operator that defines results based on two points, you should always test to check whether
the results are inclusive or exclusive.
You can also combine operators in the WHERE clause to fine-tune your result set. Listing 13-16 shows an
example of using both the BETWEEN and LIKE operators in the same WHERE statement.
Listing 13-16. Combining Multiple Operators in a WHERE Statement
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
[Date] BETWEEN '09/13/1994' AND '09/14/1994'
AND
[TitleId] LIKE 'PS%'
ORDER BY DP.PublisherName, [Title], [OrderDate]
 
 
Search WWH ::




Custom Search