Using a script that doesnt accept null but Nan i'm trying to insert null value instead of 0 in sql server table. So to do that I had an idea to create stored procedure that will cast the Nan to null float. here is the stored procedure :
create procedure [dbo].fromNanToNull(@val VARCHAR)
AS BEGIN
DECLARE @Work float
if @val like 'N%' set @Work=CAST(NULL AS float)
else set @work=CAST(@val AS float)
return @work
END
Execution :
exec [dbo].fromNanToNull 'Nan'
but instead of getting null in return i Got this message which tell that the return is forced to 0 instead. Here is the message :
The 'fromNanToNull' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.
set @Work=CAST(NULL AS float).NULLisNULL, meaning NOTHING and hence it should not be cast(ed) to any type.