Return Null if blank

Posted by VIJI Friday, July 3, 2009

About this SQL User defined function

This Function will return a null if the value of the field passed is blank..



CREATE FUNCTION dbo.FuncBlankToNull(@Input varchar(2000))
RETURNS varchar(2000) AS
BEGIN
Declare @Return as varchar(2000)
Set @Return = LTrim(RTrim(@Input))
if @Return = ''
Begin
Set @Return = Null
End
Return @Return
END




Example

dbo.FuncBlankToNull('') = Null
dbo.FuncBlankToNull('RAJ') ='RAJ'

0 Responses to Return Null if blank

Post a Comment