开发者

How to make it right? - SQL Server Query

开发者 https://www.devze.com 2023-02-10 06:20 出处:网络
I have a table in my DB called Emplyee and contains these columns : Categ - int WorkPlace - int WorkPlace1 - int

I have a table in my DB called Emplyee and contains these columns :

Categ - int
WorkPlace - int
WorkPlace1 - int
EducationalLevel - varchar(100)
System - varchar(100)
Type - varchar(100)
ApData - varchar(100)

I am making a search form and I don't know ho开发者_JS百科w to do this complicated query.

First the Categ is th main category and WorkPlace is sub category and WorkPlace1 is sub category for WorkPlace

I want to select all rows that match Categ and WorkPlace and WorkPlace1 and search for strings in other columns.

In other words, I want to search in these column EducationnalLevel, System, Type, ApData when there is match in the categories columns.

How I can do it?

Thanks in advance.


Here's one way to approach this (this assumes you define variables for all items starting with @):

declare @search varchar(100)
set @search = '%FIND_ME%'

select *
from Emplyee 
where Categ = @Categ and WorkPlace = @WorkPlace and WorkPlace1 = @WorkPlace1 and
(
   EducationalLevel like @search OR
   System like @search OR
   Type like @search OR
   ApData like @search
) 
0

精彩评论

暂无评论...
验证码 换一张
取 消