This article mainly introduces the precautions for using and and or in the SQL statement of asp. Friends in need can refer to it.
When debugging the program today, we need to use and or. If we don’t master the skills, the output structure is a bit different from what we imagined. Let’s share it here. I hope everyone will support Script Home in the future.
Can and and or not be used at the same time in asp SQL statements?
The answer is yes, here’s how to do it:
1. I am very responsible to tell you that they can be used at the same time. But it depends on the business requirements
2. Examples of usage scenarios:
Male classmates born in 2000 and 2002 in the query table
select * from student table where gender='male' and (birth year=2000 or birth year=2002)
3. In fact, or can be replaced by In in SQL, which will be more convenient to write.
For example, the above example is written using In:
select * from student table where gender='male' and year of birthIn (2000,2002)
In fact, it is to use () to expand the areas that need attention.
For example: Script House background search needs to determine when the search is js. Then some of our editors use javascript, so some things cannot be searched. Then you can refer to this method.
Core code:
select case lcase(keyarr(I)) case js sqlk=sqlk& and (title like '%&keyarr(I)&%' or title like '%javascript%') case javascript sqlk=sqlk& and (title like '%&keyarr(I )&%' or title like '%js%') case c# sqlk=sqlk& and (title like '%&keyarr(I)&%' or title like '%csharp%') case csharp sqlk=sqlk& and (title like '%&keyarr(I)&%' or title like '%c#%') case else sqlk=sqlk& and title like '%&keyarr(I) &%' end select