Skip to content
Advertisement

Why Row_Number in a view gives a nullable column

I have a view using a CTE and I want use a row number to simulate a key for my edmx in Visual Studio

When I look in properties of column I see Id bigint … NULL

And my edmx exclude this view cause don’t find a column can be used to key

When I execute my view ID have no null. I’ve all my row number.

If someone encounter this problem and resolved it … Thanks

Advertisement

Answer

SQL Server generally thinks that columns are NULL-able in views (and when using SELECT INTO).

You can convince SQL Server that this is not the case by using ISNULL():

Note: This works with ISNULL() but not with COALESCE() which otherwise has very similar functionality.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement