简体   繁体   English

如何获得这个结果

[英]how to get this result

I have a dropdown on page when user selects any value from it ; 当用户从中选择任何值时,页面上会有一个下拉菜单; i am passing that value and filtering the result. 我正在传递该值并过滤结果。 suppose if user select any bike from dropdown then from user table only those record should come which have that bike and also those records should come where user have not any bike . 假设如果用户从下拉列表中选择了任何一辆自行车,那么从用户表中只能找到拥有该自行车的那些记录,并且那些使用者没有任何自行车的记录也应该出现。

   username               vehicleID 
   =========              =======
   john                   1
   peter                  1
   maria                  2
   raso                 
   pritam                 4

if user selects vehicleID 2 then raso should also come along with maria. 如果用户选择了VehicleID 2,那么raso也应该与maria一同出现。 I do not want to use UNION for this . 我不想为此使用UNION。

IF user does not select any thing all data should come by default on page 如果用户未选择任何内容,则默认情况下所有数据都应显示在页面上

any other idea. 任何其他想法。 thanks in advance 提前致谢

Use the following query, where the @VehicleID is the SelectedValue of the dropdownlist . 使用以下查询,其中@VehicleIDdropdownlistSelectedValue

SELECT Username
FROM Table
WHERE @VehicleID IS NULL
OR VehicleID=@VehicleID
OR VehicleID IS NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM