tags:

views:

280

answers:

1

Using asp.net In the gridview select command, how can I select all records, including null, for a particular field. I have a parameter which changes with the dropdown selection. I have a default list item set to % but this will not pull records with null. I tried this: Where ((@submit LIKE '%' AND user_submit LIKE @submit OR user_submit IS NULL) OR (@submit NOT LIKE '%' AND user_submit LIKE @submit)) but am getting null records in both sides of the or statement. I aslo tried a case statement but cannot figure out how to select both % and 'is null'.

Thanks in advanced

A: 

If I'm understaning correctly I think you want to select based on a criteria but also if the field has a value of null.

Something like this should work for you

select whatever from Table_1 where whatever like '%' or whatever is null
cptScarlet
That part I already have. If the user selects something from the dropdown then I do not want records with null in the field returned. This must be base off the same parameter.
Ok, you have lost me. In your question you say you want to return both '%' and null now you are saying you don't want null. Which is it? If you don't want null then just do the query i posted but without the or clause
cptScarlet
On page load I need both, that is why I'm using the wild card. If the user selects something from the dropdown of course I do not want both but only wha they have selected.
What are the options in the drop down?
cptScarlet
The are based on what is in the database. The fields are set to varchar
So these are the names of fields in the database I assume?
cptScarlet
No, values in the database. I ran a select disctint to populate the dropdown list.
OK, so it seems like you just want to then select all rows in the database that has the value selected in the drop down list. In this case you just need to change the where clause to "where column=dropdown value" or if you want to pull all of the records that contain that value somewhere in the field you can do something like "where column like '%dropdown value%'"Is this what you were after?
cptScarlet