Results 1 to 3 of 3

Thread: how to pass NULL as an IN parameter to SQL function

  1. #1
    Join Date
    Oct 2004
    Posts
    8

    Default how to pass NULL as an IN parameter to SQL function

    I have an SQL Server 2000 function, that has 1 out parameter and 3 in parameters. The 3rd parameter is optional though. How do you use Spring's StoredProcedure object to supply the third parameter to be null?

    Any help would be appreciated.

    Below is the funtion:

    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS ON
    GO


    create function fn_Verify_Format (@instrument_id int, @fmt nvarchar(31), @fmt_id int)
    returns bit
    as
    begin

    declare @exists bit

    if @fmt_id is null
    begin
    if exists (select 1 from dcds_format where instrument_id = @instrument_id and name = @fmt)
    select @exists = 1 else select @exists = 0
    end
    else
    begin
    if exists (select 1 from dcds_format where instrument_id = @instrument_id and name = @fmt and format_id <> @fmt_id)
    select @exists = 1 else select @exists = 0
    end
    return (@exists)
    end

    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

  2. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    Have you tried just passing in a Java 'null' - it should result in the parameter being set to NULL.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Mar 2005
    Posts
    25

    Default

    That works for me:

    params.put("name",null);

    Quote Originally Posted by trisberg
    Have you tried just passing in a Java 'null' - it should result in the parameter being set to NULL.

Similar Threads

  1. Replies: 2
    Last Post: Oct 17th, 2005, 08:41 PM
  2. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  3. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  4. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM
  5. Strange Data Access Error
    By webifyit in forum Data
    Replies: 2
    Last Post: Dec 28th, 2004, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •