Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote this stored procedure to user filter the result of select but It wont work at all. I have a form with four textboxes and user can combinatorial fill the textboxes(user has not to fill all textboxes or one of them)so what is the problem?
CREATE PROCEDURE sp_search

  @minprice bigint=null,
  @maxprice bigint=null,
  @minarea int=null,
  @maxarea int=null,
  @location nvarchar(50)=null,
  @kind nvarchar(50)=null

AS

  SELECT * FROM Landtbl
      WHERE ((@minprice is null and @maxpriceis null) 
       or ([price] between @minprice and @maxprice))
         and
           ((@minarea is null and @maxarea is null) 
            or ([area] between @minarea and @maxarea))
              and   ((@location is null)or([location]=@location))
                and   ((@kind is null) or ([kind]=@kind))
Posted
Updated 23-Jan-15 9:59am
v2
Comments
Zoltán Zörgő 23-Jan-15 16:09pm    
Are you sure, that in null is passed when user lets field empty?
Member 11306411 23-Jan-15 16:25pm    
no but Its not my problem now,I know it has error in c# we cant conver empty textbox to int64(because of my two bigint variable)but when I pass parameteres by myself It wont work
cvogt61457 23-Jan-15 16:18pm    
What do you mean my "It won't work at all?"
Do you get an error?
No data?
Wrong data?
Do you get any results under any circumstances?
Member 11306411 23-Jan-15 16:24pm    
I get nothing.It return nothing to my datagrideview.I guess Its logiclly correct but it wont work.What do you prefer in this condition?
ZurdoDev 23-Jan-15 16:25pm    
A quick glance tells me it is OK which means Zoltan is likely correct. Are you sure NULL is getting passed in when nothing is selected.

Are you also sure it isn't working?

1 solution

You appear to have have an error in your WHERE statement. You have @maxpriceis null. It should read @maxprice is null.You have omitted the space between maxprice and is.

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900