abhijitm Posted November 1, 2006 Share Posted November 1, 2006 i have a table wid one column 'B' as primary key and another column 'S' which can hold null values. Now i want to write a query such that[1] i supply a value for 'B' [2] either a value or NULL for 'S'If the field 'S' has some value other than NULL then the rows corresponding to B AND S for the given values are selected and if field 'S' has null then all the rows with value supplied to 'B' are seleceted. Please help me with the query.... Link to comment Share on other sites More sharing options...
aspnetguy Posted November 1, 2006 Share Posted November 1, 2006 sorry, I don't understand your condition. Link to comment Share on other sites More sharing options...
abhijitm Posted November 1, 2006 Author Share Posted November 1, 2006 sorry, I don't understand your condition.In my querry i am using a variable for B and S( they r the columns of a table) In case the value for field S in provided as NULL then i want all the rows with given value of column 'B'and if field 'S' is passed some non-null value then i want the rows having given values for B and SFor example B S1 121 1312 142 now i want to write a querry such that if i pass 1 for B and 12 for S then my querry returns row 1 only and if i pass 1 for B and NULL for S then i get row 1,2 and 3. Hopei make my self clearer now Link to comment Share on other sites More sharing options...
aspnetguy Posted November 1, 2006 Share Posted November 1, 2006 I think you would be better off writing 2 seperate queries and then using a server-side language to determine which wuery to run. Link to comment Share on other sites More sharing options...
pulpfiction Posted November 1, 2006 Share Posted November 1, 2006 Like ASPNETGUY's idea if valuefor_col_S == NULL thensqlquery = "Select B,S from table_name where B = ' " + valuefor_col_B + "'"elsesqlquery = "Select B,S from table_name where B = " + valuefor_col_B + "and S =" + valuefor_col_Send if Link to comment Share on other sites More sharing options...
abhijitm Posted November 2, 2006 Author Share Posted November 2, 2006 thnks a lot ..but i m not looking for this solution ...i want a single query.... Link to comment Share on other sites More sharing options...
abhijitm Posted November 2, 2006 Author Share Posted November 2, 2006 GOT THE SOLUTION the following works for the above ::select B,S from <TABLE_NAME> Where B = :b_value AND (S=:s_value OR :s_value='<dummy_value>' OR :s_value is NULL ) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now