私はSPを下回っていて、時間がかかりすぎて、ついに停止しました
EXEC MemberListing 1,20,'','','RegDate','Desc',0
パラメータに値を渡すと機能し@IP
ます。理由はわかりません。
Create PROCEDURE MemberListing
@PageNum as Int,
@PerPageResult as Int,
@Username as nvarchar(50),
@IP as varchar(50),
@sortColumn as Varchar(50),
@sortOrder as Varchar(4),
@TotalCount as int OUTPUT
AS
BEGIN
declare @Temp Table(RowNum int, id bigint, Username nvarchar(50), Email nvarchar(50), RegDate DateTime, Country varchar(25),
LastLogin DateTime, IsGoldMember varchar(1))
declare @sort varchar(50)
if @IP = ''
BEGIN
print 'if'
SET FMTONLY OFF;
Insert into @Temp
Select ROW_NUMBER() over (order by
case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'id' then id end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Username' then Username end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Email' then Email end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Country' then Country end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end ASC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'id' then id end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Username' then Username end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Email' then Email end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Country' then Country end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end DESC
) As RowNum, * From (
SELECT
m.id,m.login as Username,m.email as Email,m.registrationdate as RegDate,c.name as Country,m.lastlogindate as LastLogin,
CASE WHEN (r.description='goldmember' or r.description='goldmember_forever') then 1 end As IsGoldMember
from member m
join country c on m.country_id = c.id
join user_role ur on m.id=ur.member_id
join role r on r.id=ur.role_id
left join lastip l on m.id=l.user_id
where r.description <> 'administrator' and m.login like @Username+'%'
) as aab
Select * from @Temp Where RowNum> @PageNum-1 and RowNum<@PerPageResult+@PageNum
order by
case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'id' then id end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Username' then Username end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Email' then Email end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Country' then Country end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end ASC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'id' then id end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Username' then Username end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Email' then Email end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Country' then Country end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end DESC
END
ELSE
BEGIN
print 'else'
SET FMTONLY OFF;
Insert into @Temp
Select ROW_NUMBER() over (order by
case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'id' then id end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Username' then Username end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Email' then Email end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Country' then Country end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end ASC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'id' then id end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Username' then Username end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Email' then Email end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Country' then Country end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end DESC
) As RowNum, * From (
SELECT
m.id,m.login as Username,m.email as Email,m.registrationdate as RegDate,c.name as Country,m.lastlogindate as LastLogin,
CASE WHEN (r.description='goldmember' or r.description='goldmember_forever') then 1 end As IsGoldMember
from member m
join country c on m.country_id = c.id
join user_role ur on m.id=ur.member_id
join role r on r.id=ur.role_id
left join lastip l on m.id=l.user_id
where r.description <> 'administrator' and m.login like @Username+'%' and l.address = @IP
) as aa
Select * from @Temp Where RowNum> @PageNum-1 and RowNum<@PerPageResult+@PageNum
order by
case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'id' then id end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Username' then Username end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Email' then Email end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'Country' then Country end ASC
, case when @sortOrder <> 'ASC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end ASC
, case when @sortOrder <> 'ASC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end ASC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'id' then id end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Username' then Username end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Email' then Email end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'RegDate' then RegDate end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'Country' then Country end DESC
, case when @sortOrder <> 'DESC' then cast(null as datetime) when @sortColumn = 'LastLogin' then LastLogin end DESC
, case when @sortOrder <> 'DESC' then 0 when @sortColumn = 'IsGoldMember' then IsGoldMember end DESC
END
END
@IPパラメータに''を渡すと、以下のエラーが発生します。
if
Msg 8152, Level 16, State 2, Procedure MemberListing, Line 24
String or binary data would be truncated.
The statement has been terminated.
(0 row(s) affected)