![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got a search form where users can search for records from the db. The App calls a stored procedure which executes the sql below. The form has two search criteria users have requested, 'labno' and 'DateAssayReq'. The App works well for the date criteria and will find the correct record(s), but will not return any records whatever I enter for the labno, even though I know the labno exists in the db. Can someone see what I've done wrong? |
#3
| |||
| |||
|
|
M Joomun (m.a.joomun (AT) qmul (DOT) ac.uk) writes: I've got a search form where users can search for records from the db. The App calls a stored procedure which executes the sql below. The form has two search criteria users have requested, 'labno' and 'DateAssayReq'. The App works well for the date criteria and will find the correct record(s), but will not return any records whatever I enter for the labno, even though I know the labno exists in the db. Can someone see what I've done wrong? The part with datalength looks funky. "DataLength(@DateAssayReq)" will never be 0. It will be 3 or NULL. Use: WHERE (@labno IS NULL OR LabNo = @labno) AND (@DateAssayReq IS NULL OR DateAssayReq = @DateAssayReq) Also make sure that you pass NULL for search conditions that do not apply. |
#4
| |||
| |||
|
|
Thanks for your response. The syntax you gave was what I was trying originally and there's no difference in the results returned; correct results if 'DateAssayReq' is used as search criteria, no results returned if labno is used, either on it's own or in conjunction with 'DateAssayReq'. Any other ideas? |
#5
| |||
| |||
|
|
On Mon, 18 Oct 2010 09:32:39 +0100, M Joomun wrote: Thanks for your response. The syntax you gave was what I was trying originally and there's no difference in the results returned; correct results if 'DateAssayReq' is used as search criteria, no results returned if labno is used, either on it's own or in conjunction with 'DateAssayReq'. Any other ideas? Hi M Joomun, That might be caused by a mismatch between the data type of the parameter and the data type of the column. Can you post the exact structure of the table, as a CREATE TABLE statement? (You can use the generate function in SSMS to get this, or if you have your table creation scripts in source control, you can use those). |
#6
| |||
| |||
|
|
Thanks for the reply. As requested, below is the structure of the table in question. Not sure if you wanted everything the create statement put out, but shout if you do: CREATE TABLE [dbo].[tblAssay]( [AssayID] [int] IDENTITY(1,1) NOT NULL, [ADtdate] [datetime] NULL, [ADtTime] [datetime] NULL, [LabNo] [nvarchar](6) NULL, [AssayTy] [smallint] NULL, [ReasonRepeat] [tinyint] NULL, [DateAssRequested] [datetime] NULL, [TimeAssRequested] [datetime] NULL, [PersonReq] [smallint] NULL, [RepeatedYN] [smallint] NULL, [DateRepeated] [datetime] NULL, [DtRepeatDy] [nvarchar](9) NULL, [PersonRepeat] [smallint] NULL, [ReasonNotRepeated] [smallint] NULL, [LIMSUpdateYN] [smallint] NULL, [DateAssayReq] [date] NULL, CONSTRAINT [aaaaatblAssay_PK] PRIMARY KEY NONCLUSTERED |
![]() |
| Thread Tools | |
| Display Modes | |
| |