Advertisement

10.01.2008 at 12:56PM PDT, ID: 23779493
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Query/Stored Procedure question.

Asked by natloz in MS SQL Server

Tags:

---------------------------------------------------------
I am trying to get the number of rows that a subquery returns inorder to perform paging (need to find out remainder of (total records / records per page) for displaying last page records).

The value for @INNERQUERY is dynamic SQL which returns all the rows that meet the criteria. I need to capture the total records inorder to perform my calculation.

I can not figure out why I am getting the error message. I believe I have all the bases covered, but obviously I am missing something. I read that when using OUTPUT that it is a 'text' value which is why I am assigning the count to @varRowsOUT.

Code with in the stored Proc:

declare @varRowCount as  varchar(4)
declare @ROWSQUERY as varchar(5000)
declare @Params as varchar(500)

set @ROWSQUERY = N'SELECT @varRowsOUT = count(*) FROM (' + @INNERQUERY + ') as SubQuery'
set @Params = N'@varRowsOUT varchar(4) OUTPUT'

      
Exec sp_executesql
      @ROWSQUERY,
      @Params,
      @varRowsOUT = @varRowCount OUTPUT;

select @varRowCount

Results in:
Msg 214, Level 16, State 2, Procedure sp_executesql, Line 267
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.


I've already tried:
1)      Exec sp_executesql
      @statement = @ROWSQUERY,
      @Params = N'@varRowsOUT varchar(4) OUTPUT',
      @varRowsOUT = @varRowCount OUTPUT;

2) Read many examples from many sources (Please don't say "Read BoL")
3) Copy-Pasted an online example for Northwind Db and played with it trying to figure it out.


-----------------
Just to clarify, print(@ROWSQUERY) shows that the query is (which executes perfectly):

SELECT @varRowsOUT = count(*) FROM
      (select top 150      a.intShopControlNumber,      a.pkShopDrawingID
      from tblShopDrawing a
      left join tblBillOfMaterials bom on fkShopDrawingID = pkShopDrawingID
      left join tblMaterialCodeSize mcs on bom.fkMaterialCodeSizeID = pkMaterialCodeSizeID
      left join tblMaterialCode mc on mcs.fkMaterialCodeID = pkMaterialCodeID
      inner join tblDesignDocument b on pkDesignDocumentID = a.fkDesignDocumentID
      inner join tblDesignDocument c on c.pkDesignDocumentID = a.fkDesignDocumentID_Isometric
      inner join tblShopDrawingRevision d on d.fkShopDrawingID = a.pkShopDrawingID
      inner join tblDesignDocumentRevision e on e.pkDesignDocumentRevisionID = d.fkDesignDocumentRevisionID
      left join tblHoldHistory f on f.fkDesignDocumentID = b.pkDesignDocumentID
      left join tblHoldHistory g on g.fkDesignDocumentID = a.fkDesignDocumentID_Isometric
      left join tblHoldType h on h.pkHoldTypeID = f.fkHoldTypeID  
      where a.fkProjectID = 70
      and e.bolCurrent = 1  
      and c.varDesignDocumentNumber LIKE 'M2%'
      GROUP BY a.intShopControlNumber, a.pkShopDrawingID  
      ORDER BY intShopControlNumber ASC
      ) as SubQuery

Can anyone help me figure what it is I am missing?

Thanks in advance.
--------------------------------------------------------------------------------------------Start Free Trial
[+][-]10.01.2008 at 01:01PM PDT, ID: 22618396

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: SQL
Sign Up Now!
Solution Provided By: xDJR1875
Participating Experts: 3
Solution Grade: A
 
 
[+][-]10.01.2008 at 01:01PM PDT, ID: 22618403

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10.01.2008 at 01:09PM PDT, ID: 22618481

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628