Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 OUTPUT @count =no of records returnd by dynamic where clause
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 08/18/2005 :  07:57:22  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Arvind writes "i want to create a stored procedure returns an OUTPUT variable containing the no. of records given by a query, the query being dynamic.
Preferrably the query should also be passed as a parameter to the stored procedure...If not,it should be constructed in the SP and a Part of the where clause is dependant on the value of another variable passed to the SP.

How should the query be constructed, executed, and then the Count(*) value returned?

"WHERE <condition1> AND <condition 2> ;

"AND <condition 2> " may exist or may not exist in the query; it is dependant."


United Kingdom
22859 Posts

Posted - 08/18/2005 :  08:04:05  Show Profile  Reply with Quote
Hi Arvind, Welcome to SQL Team!

Something like:

    @strWhere varchar(8000),
    @intRowCount int OUTPUT
DECLARE @strSelect varchar(8000)

    SELECT @strSelect = 'SELECT * FROM dbo.MyTable '

    EXEC (@strSelect + @strWhere)
    SELECT @intRowCount = @@ROWCOUNT

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000