Home SQL stored procedure query to clear date field if NULL
Reply: 0

SQL stored procedure query to clear date field if NULL

user907
1#
user907 Published in May 25, 2018, 6:54 pm

I'm not a SQL expert, but have a stored procedure query to insert a record into a table. I have a select call in my insert query to replace a NULL DateTime field to ''. But for some reason it doesn't work. The DateTime field is still NULL in the database table after the insert. Could someone look at the query below let me know if the select call to clear the DateTime field is valid to do in the same insert call.

CREATE PROC pCreate_DBQuery
( 
   @Message varchar(max),
   @DateTime smalldatetime
)
AS
BEGIN
    INSERT INTO dbo.TestTbl(Message, DateTime)
    VALUES (@Message, @DateTime)
    SELECT ISNULL(@ProcessedDateTime,'1900-01-01') AS [Changed Processed 
    Date]
    SELECT SCOPE_IDENTITY()
END

This command

EXEC pCreate_DBQuery 'None', NULL

Table results from insert

None, NULL
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319294 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO