Select statment from multiple tables, with variable input

前端 未结 3 1732
自闭症患者
自闭症患者 2021-01-16 09:17

I have two tables: AreaCode and EquipmentNumber.

+------------------------------------+
| AreaCd                             |
|---         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 09:28

    SELECT e.Number, e.Type, a.Code
    FROM EqNum e INNER JOIN AreaCd a
    ON e.AreaId = a.AreaId
    WHERE (@Number IS NULL OR e.Number = @Number)
    AND (@Type IS NULL OR e.Type = @Type)
    AND (@Code IS NULL OR a.Code = @Code)
    

    To learn how to use parameters with ADO.NET, click here.

    Setting parameters would look something like this:

    command.Parameters["@Number"].Value = (string.IsNullOrEmpty(number) ? (object) DBNull.Value : number);
    

提交回复
热议问题