Hello everyone,
I am using SQL Server 2008 Enterprise. I am using the following statement in SQL Server Management Studio as a part of a store procedure, and there is following error (compile error when I press F5 to run the store procedure). But when I removed count(), all error disappears. Any ideas what is wrong with count()? Another question is, my purpose is to return the total number of matched result and only return a part of result to implement paging (using tt.rowNum between @startPos and @requireCount + @startPos-1), any ideas how to implement that?
SELECT *
FROM (SELECT count(*), t.id,t.AdditionalInfo, ROW_NUMBER()
OVER (order by t.id) AS rowNum
FROM dbo.foo t
CROSS APPLY t.AdditionalInfo.nodes('/AdditionalInfo')
AS MyTestXMLQuery(AdditionalInfo)
WHERE
(Tag4=''+@InputTag4+'' OR Tag5=''+@InputTag5+'')
and (MyTestXMLQuery.AdditionalInfo.value
('(Item[@Name="Tag1"]/@Value)[1]', 'varchar(50)')
LIKE '%'+@Query+'%'
or MyTestXMLQuery.AdditionalInfo.value
('(Item[@Name="Tag2"]/@Value)[1]', 'varchar(50)')
LIKE '%'+@Query+'%'
or MyTestXMLQuery.AdditionalInfo.value
('(Item[@Name="Tag3"]/@Value)[1]', 'varchar(50)')
LIKE '%'+@Query+'%') ) tt
WHERE tt.rowNum between @startPos and @requireCount + @startPos-1
Error message,
Column 'dbo.foo.ID' is invalid in the select list
because it is not contained in either an aggregate function
or the GROUP BY clause.
No column name was specified for column 1 of 'tt'.
thanks in advance, George