Question : sql stored procedure select compare dates null issue

I'm having problems getting my expected results when a NULL date comes into play.  From my asp page using vbscript I execute this stored procedure (see code sample), which also passes the values used for the 5 variables.  I don't have any issues with the other 4 variables, just the date.

Provided the @m_retrieve_id5 is passed a date like   30 October 2009   it will find the match from my select statement as long as the other WHERE statements are true.

Issue I have is when @m_retrieve_id5 is passed NULL or Null it is not finding the match when executing my select statement.  The  h_post_date  field in the SQL table will not always have a vaild date, some are NULL and I might be trying to find those.  I can adjust the stored procedure or the vbscript passing the value, just need help with that...

Regards,
Torrey
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER PROCEDURE [dbo].[sp_host_upload_dup_claim_retrieve]
	@m_retrieve_id1 varchar(20),    /* Account #     */
	@m_retrieve_id2 varchar(11),    /* Soc Sec #     */
	@m_retrieve_id3 numeric(10,2),  /* w/o Balance   */
	@m_retrieve_id4 numeric(10,2),  /* Cur Balance   */
	@m_retrieve_id5 datetime        /* Post Date     */
AS
BEGIN
	SET NOCOUNT ON;

	SELECT claim_id	FROM host_claims 
	WHERE h_account_no = @m_retrieve_id1
	and h_socsec       = @m_retrieve_id2 
	and h_wo_balance   = @m_retrieve_id3
	and h_cur_balance  = @m_retrieve_id4
	and h_post_date    = @m_retrieve_id5
END
GO

Answer : sql stored procedure select compare dates null issue

then please try my 3 post, they should be ok...

and h_post_date    = @m_retrieve_id5
-->
and ((h_post_date   = @m_retrieve_id5) or (@m_retrieve_id5 is null))
or
and ((isnull(h_post_date,'')   = isnull(@m_retrieve_id5,''))
Random Solutions  
 
programming4us programming4us