SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
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."

Kristen
Test

United Kingdom
22415 Posts

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

Something like:

CREATE PROCEDURE dbo.MySProc
    @strWhere varchar(8000),
    @intRowCount int OUTPUT
AS
DECLARE @strSelect varchar(8000)

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

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

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