Error converting data type varchar

前端 未结 8 1490
既然无缘
既然无缘 2020-12-20 15:07

I currently have a table with a column as varchar. This column can hold numbers or text. During certain queries I treat it as a bigint column (I do

8条回答
  •  一整个雨季
    2020-12-20 15:24

    To answer your question about the error message: when you reference a view name in another query (assuming it's a traditional view not a materialised view), SQL Server effectively does a macro replacement of the view definition into the consuming query and then executes that.

    The advantage of doing this is that the query optimiser can do a much better job if it sees the whole query, rather than optimising the view separately as a "black box".

    A consequence is that if an error occurs, error descriptions may look confusing because the execution engine is accessing the underlying tables for the data, not the view.

    I'm not sure how materialised views are treated, but I would imagine that they are treated like tables, since the view data is cached in the database.

    Having said that, I agree with previous answers - you should re-think your table design and separate out the text and integer data values into separate columns.

提交回复
热议问题