クロスアプライを使用してテーブルからフィールド「tagtext」を取得し、各タグテキストを別のテーブルのTagsという新しいフィールドのエントリとしてまとめるストアドプロシージャがあります。ただし、クロスアプライがどのように機能するかについては気にせず、エラーが発生しているようです:無効なオブジェクトmyArticles。
私のspからの関連コードは次のとおりです。
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
declare @RowStart int
declare @RowEnd int
IF (@Page=1)
Begin
set @RowStart=(@Page-1)*(@PageLen)
set @RowEnd=(@RowStart+@PageLen);
END
ELSE
BEGIN
set @RowStart=((@Page-1)*(@PageLen))+1
set @RowEnd=((@RowStart+@PageLen))-1
END;
With myArticles as
(select ROW_NUMBER() over (ORDER BY publicationdate DESC) as 'RowNumber',*
From article_v
where articleID in(select articleID from savedarticle where userID= @UserID) and
title like '%'+@keyword1+'%' and
title like '%'+@keyword2+'%' and
title like '%'+@keyword3+'%' and
title like '%'+@keyword4+'%' and
title like '%'+@keyword5+'%'
)
(select mA.*,
isnull(left(Tags,len(Tags)-1),'') as Tags
from myArticles mA
cross apply (select tagtext +', '
from usertag uTag
where uTag.userID=@userID and uTag.usertagID in(select usertagID from articletag aTag where aTag.articleID=mA.articleID)
for xml path('')) ca(Tags)
)
select
rownumber,journalID,journalname,articleID,title,publicationdate,medabbr, authors, Tags
from myArticles where RowNumber Between @RowStart and @RowEnd
END
GO
次に、spを使用しているWebサービスは次のとおりです。
<WebMethod()> _
Public Function GetSavedArticlesWithAbbr(ByVal mobileGUID As String, ByVal pageNum As Integer, ByVal pageLen As Integer, ByVal keywords As String) As List(Of ipadArticle)
Dim result As New List(Of ipadArticle)
keywords = HttpUtility.UrlDecode(keywords)
Dim tempParamKW() As String = {"", "", "", "", ""}
Dim tempKW() As String = keywords.Split(" ")
Dim tempILoop As Integer = 0
For Each s As String In tempKW
tempParamKW(tempILoop) = s.Trim
tempILoop += 1
Next
Dim simpuser As SimpleUser = utils.GetSimpleUserInfoFromMobileGUID(mobileGUID)
If simpuser.isValid Then
Dim lq As New lqDFDataContext
Dim var = lq.mobile_GetSavedArticlesJW(simpuser.UserID, tempParamKW(0), tempParamKW(1), tempParamKW(2), tempParamKW(3), tempParamKW(4), pageNum, pageLen)
For Each a_var In var
Dim ipadartcicle As New ipadArticle()
ipadartcicle.ArticleID = a_var.articleID
ipadartcicle.PublishedOn = a_var.publicationdate
ipadartcicle.Title = a_var.title
ipadartcicle.MedAbbr = a_var.medabbr.Replace(" ", "-").ToLower()
Dim tempTags() As String = a_var.Tags.Split(",")
For Each t As String In tempTags
ipadartcicle.Tags.Add(t)
Next
Dim tempAuthors() As String = a_var.Authors.Split(",")
For Each a As String In tempAuthors
ipadartcicle.Authors.Add(a)
Next
result.Add(ipadartcicle)
Next 'this is where i get the error
End If
Return result
End Function