I have two views with the same columns. One of the columns in the first view is generated on the fly and set to NULL , and the same column in the other view has values stored as varchar . I have a stored procedure that looks like this:
ALTER PROCEDURE [dbo].[mi_GetLearners] (@centrename nvarchar(200)) AS SELECT [centrename] ,[Name] ,[Username]
DB1 is on SQL Server 2008 R2
DB2 is on SQL Server 2005
When starting the stored procedure, I get the following error:
Msg 245, level 16, state 1, line 1 Conversion error while converting value varchar 'someusername' for int data type.
Why is he trying to convert the value to int datatype since the other column is set to NULL ? If I instead changed the second column from NULL to ' ' , then the stored process works fine ... I am really confused why the union between the varchar column and the NULL column generated in the select statement will throw such an error ... any ideas?
EDIT: I'm looking for an explanation, not a solution ...
EDIT 2: Running the following code:
CREATE VIEW vw_myview AS SELECT NULL AS MyColumn EXECUTE sp_help vw_myview
Return:
Type Column_name int MyColumn
source share