Home Forums SQL Server 2005 T-SQL (SS2K5) update statement with isnull and nullif functions. RE: update statement with isnull and nullif functions.

  • As being minimalist, the following single line will also work to set your param to null if it is a blank (or spaces) without any trims and checks for length (it would also work if your @path param would be of CHAR datatype):

    SET @path = NULLIF(@path,'')

    Actually, you don't need even that, just use:

    UPDATE m

    SET

    Path = ISNULL(@Path,NULLIF(m.path,'')), -- don't update when no path supplied

    PathReadOnly = ISNULL(@PathReadOnly,m.PathReadOnly)

    FROM dbo.Mytable as m

    WHERE Code = @Code

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]