Home > database >  SQL server the query code, how to fuzzy like?
SQL server the query code, how to fuzzy like?

Time:11-19

Now check name is specified the name
If I want to check the name of (*)
Excuse me, what can be achieved like '% Ming'
Thank you thank you


Declare @ Nick nvarchar (100)='Ming'
Declare @ SQL nvarchar (4000)
Declare @ dbIdx int=1

If OBJECT_ID (' tempdb for. Dbo. # NickList ') is not null
Drop table # NickList
If OBJECT_ID (' tempdb for. Dbo. # NickDetail ') is not null
Drop table # NickDetail

The create table # NickList
(
QQNum int,
Nick nvarchar (20),
The Age int,
Gender int,
Auth int,
QunNum int,
The Title nvarchar (22),
QunText nvarchar (80)
)
The create table # NickDetail
(
QunNum int,
The Title nvarchar (22),
QunText nvarchar (80)
)

While @ dbIdx & lt; 11=
The begin
Declare @ tblIdx int=1
Declare @ tblName nvarchar (50)

While @ tblIdx & lt;=100
The begin
Set @ tblName='GroupData + CONVERT (nvarchar (2), @ dbIdx) +'. The dbo. The Group '
The set @ tblName +=the CONVERT (nvarchar (5), (@ dbIdx - 1) * 100 + @ tblIdx)

The set @ SQL='select QQNum, Nick, Age, Gender, Auth, QunNum from'
SQL +=set @ @ tblName + 'where Nick=' + char (39) + the CONVERT (nvarchar (15), @ Nick) + char (39)

Print @ SQL
Insert into # NickList (QQNum, Nick, Age, Gender, Auth, QunNum) exec (@ SQL)

Print @ tblname + 'OK'

The set @ tblIdx +=1
End

The set @ dbIdx +=1
End

Select * from # NickList order by QQNum asc
- group by QQNum order by QQNum asc, count (distinct QQNum)

CodePudding user response:

 

Declare @ Nick nvarchar (100)='Ming'
Declare @ SQL nvarchar (4000)
Declare @ dbIdx int=1

If OBJECT_ID (' tempdb for. Dbo. # NickList ') is not null
Drop table # NickList
If OBJECT_ID (' tempdb for. Dbo. # NickDetail ') is not null
Drop table # NickDetail

The create table # NickList
(
QQNum int,
Nick nvarchar (20),
The Age int,
Gender int,
Auth int,
QunNum int,
The Title nvarchar (22),
QunText nvarchar (80)
)
The create table # NickDetail
(
QunNum int,
The Title nvarchar (22),
QunText nvarchar (80)
)

While @ dbIdx & lt; 11=
The begin
Declare @ tblIdx int=1
Declare @ tblName nvarchar (50)

While @ tblIdx & lt;=100
The begin
Set @ tblName='GroupData + CONVERT (nvarchar (2), @ dbIdx) +'. The dbo. The Group '
The set @ tblName +=the CONVERT (nvarchar (5), (@ dbIdx - 1) * 100 + @ tblIdx)

The set @ SQL='select QQNum, Nick, Age, Gender, Auth, QunNum from'
-- set @ +=@ tblName + SQL 'where Nick=' + char (39) + the CONVERT (nvarchar (15), @ Nick) + char (39)
SQL +=set @ @ tblName + 'where Nick Like' '%' + char (39) + the CONVERT (nvarchar (15), @ Nick) + char (39) + '%'


Print @ SQL
Insert into # NickList (QQNum, Nick, Age, Gender, Auth, QunNum) exec (@ SQL)

Print @ tblname + 'OK'

The set @ tblIdx +=1
End

The set @ dbIdx +=1
End

Select * from # NickList order by QQNum asc
- group by QQNum order by QQNum asc, count (distinct QQNum)

CodePudding user response:

A friend you know?

CodePudding user response:

Written statement is wrong, to tidy it up yourself

CodePudding user response:

reference shoppo0505 reply: 3/f
statement to write wrong, to tidy it up by yourself
remarkably specified name can be found out, just don't know how to add fuzzy like?

CodePudding user response:

To the best post table data

CodePudding user response:

To the column B the parse XML data inside out, in the form of a table stored in the database table, and then to calculate,

The process must be more painful for the first time, but should be the most effective way,
  • Related