Home > front end >  [scattered points] [share] technology SAO operation: using SQL inside like statements achieve precis
[scattered points] [share] technology SAO operation: using SQL inside like statements achieve precis

Time:09-26

[scattered points] [share] technology SAO operation: using SQL inside like statements achieve precise search query - a session user id is in a field of string

As title, dare not exclusive, sharing, maybe someone with,

[problem description]
How to use the SQL query whether a session user id in a table of a field of string,
Such as: my BBS database table has a field called arrayuserid, deposit of an array of several user id, a value of 1,10,20,31,14,25,36,
I want to check the user id=1 (assuming the session (" userid ")=1) whether the record in the array,

[my two writing]
A, SQL="SELECT * FROM BBS where arrayuserid like '%" & amp; The session (" userid ") & amp;" "
% 'Second, SQL="SELECT * FROM BBS where" & amp; The session (" userid ") & amp;" In arrayuserid
"
[error analysis]
Obviously, the above two kinds of method can achieve the above requirements,
The first will take id 1 (assuming the session (" userid ")=1) record of all find out, because like statements inside the "%" said wildcard,
The second can't find any records, after the test, in statement to support this writing: SQL="where the SELECT * FROM BBS" & amp; The session (" userid ") & amp;" ,10,20,31,14,25,36 in (1) ", but this can't realize the library query, , please master the second statement in writing if the change is only available? Heel stick add trouble, thank you!

[written] right
asked baidu, have superior give written below:
SQL="SELECT * FROM where a ', '+ arrayuserid +', 'like' %," & amp; The Session (" userid ") & amp;" %, '"
Quite so constructed such like:
, 1,10,20,31,14,25,36, like, 1,
Such use of structure variables like statements, regardless of the session (" userid ") in the beginning or end of an array, can achieve precise search, and won't match to all take 1 (assuming the session (" userid ")=1) data, really is too high and clear!

CodePudding user response:

Scattered points, everyone does?
How no one reply

CodePudding user response:

  •  Tags:  
  • ASP
  • Related