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)