I have a datetime field in a table called dbo.Traffic
I am trying to aggregate traffic data by day. I am planing on creating a schemabound view and adding an index.
CREATE VIEW [dbo].[vwTraffic] WITH SCHEMABINDING AS
SELECT CONVERT(date, CreateDate) as CreateDate, Circuit, Fuseaction,
COUNT(CreateDate) AS activity
FROM dbo.Traffic WITH (NOLOCK)
GROUP BY CONVERT(date, CreateDate), Circuit, Fuseaction
In the base table, CreateDate is not nullable. However, as soon as I create a view and convert it to a date, it becomes nullable.
This is because of how computed columns behave in terms of nullability. Check it in here on MSDN:
You can use that as your
CreateDate
. You don't have to worry about the constant value as you should never haveNULL
: