Inserting "null" (literally) in to a stored procedure parameter.
Posted
by Nazadus
on Stack Overflow
See other posts from Stack Overflow
or by Nazadus
Published on 2010-04-13T18:30:43Z
Indexed on
2010/04/13
18:33 UTC
Read the original article
Hit count: 405
tsql
|sql-server-2005
I'm trying to insert the word "Null" (literally) in to a parameter for a stored procedure. For some reason SqlServer seems to think I mean NULL and not "Null". If I do a check for
IF @LastName IS NULL // Test: Do stuff
Then it bypasses that because the parameter isn't null.
But when I do:
INSERT INTO Person (<params>) VALUES (<stuff here>, @LastName, <more stuff here>); // LastName is 'Null'
It bombs out saying that LastName doesn't accept nulls. I would seriously hate to have this last name, but someone does... and it's bombing the application. We're using SubSonic 2.0 (yeah, it's fairly old but upgrading is painful) as our DAL and stepping through it, I see it does create the parameters properly (for what I can tell).
I've tried creating a temp table to see if I could replicate it manually but it seems to work just fine. Here is the example I create:
DECLARE @myval VARCHAR(50)
SET @myval = 'Null'
CREATE TABLE #mytable( name VARCHAR(50))
INSERT INTO #mytable VALUES (@myval)
SELECT * FROM #mytable
DROP table #mytable
Any thoughts on how I can fix this?
© Stack Overflow or respective owner