我有这张桌子
CREATE TABLE [dbo].[HRCandidateProject](
[ProjectId] [bigint] IDENTITY(1,1) NOT NULL,
[orgid] [int] NULL,
[uid] [int] NULL,
[CandidateId] [bigint] NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ProjectName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FromDate] [datetime] NULL,
[ToDate] [datetime] NULL,
[SkillSet] [varchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Role] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Client] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ProjectDiscription] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TotalExperience][int]
CONSTRAINT [PK_HRCandidateProject] PRIMARY KEY CLUSTERED
(
[ProjectId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
在下拉列表中我的总体验值为1 - 2年,2 - 4年,4 - 7年,超过7年
我想写一个显示数据的查询,如果我在下拉列表中选择1 - 2年,它必须只显示那些有1到2年经验的候选人
答案 0 :(得分:1)
通过设置地图来定义下拉列表值:
<asp:DropDownList ID="Experience" runat="server">
<asp:ListItem Value="1">1-2 Years</asp:ListItem>
<asp:ListItem Value="2">2-4 Years</asp:ListItem>
<asp:ListItem Value="3">4-7 Years</asp:ListItem>
<asp:ListItem Value="4">More than 7 Years</asp:ListItem>
</asp:DropDownList>
在您的查询中,检查OR分支中的每个值,如果值与所选值匹配,则根据经验过滤:
SELECT *
FROM HRCandidateProject
WHERE
(
@SelectedExperience = 1
AND TotalExperience BETWEEN 1 AND 2
)
OR (
@SelectedExperience = 2
AND TotalExperience BETWEEN 2 AND 4
)
OR (
@SelectedExperience = 3
AND TotalExperience BETWEEN 4 AND 7
)
OR (
@SelectedExperience = 4
AND TotalExperience > 7
)
有几点需要注意: