Guest_imported
New member
- Jan 1, 1970
- 0
Hi,
I am writing a stored procedure which needs to execute some dynamic TSQL SELECT statement and find out how many rows were returned.
It is written in a similar fashion to the following:
------------------------------------------------------------
...
DECLARE @sql
DECLARE @rowsfound
SELECT @sql = 'SELECT ... (etc)'
EXEC (@sql)
SELECT @rowsfound = @@rowcount
...
------------------------------------------------------------
N.B. In the situation where I have used code similar to the above, the number of rows returned is always 1 or 0.
The code works fine if I execute it from the Query Analyser. However, if I execute it from a call in my ASP program (which is ultimately where I want to use it from), then @@rowcount always seems to return 0 regardless of whether the correct answer is 1 or 0. The command used to start the stored procedure is exactly the same in both cases.
Does anyone know if this is a known "feature" in SQL or does anyone have an alternative way of obtaining the number of rows returned by the dynamic SELECT call?
Thanks in advance,
Simon.
I am writing a stored procedure which needs to execute some dynamic TSQL SELECT statement and find out how many rows were returned.
It is written in a similar fashion to the following:
------------------------------------------------------------
...
DECLARE @sql
DECLARE @rowsfound
SELECT @sql = 'SELECT ... (etc)'
EXEC (@sql)
SELECT @rowsfound = @@rowcount
...
------------------------------------------------------------
N.B. In the situation where I have used code similar to the above, the number of rows returned is always 1 or 0.
The code works fine if I execute it from the Query Analyser. However, if I execute it from a call in my ASP program (which is ultimately where I want to use it from), then @@rowcount always seems to return 0 regardless of whether the correct answer is 1 or 0. The command used to start the stored procedure is exactly the same in both cases.
Does anyone know if this is a known "feature" in SQL or does anyone have an alternative way of obtaining the number of rows returned by the dynamic SELECT call?
Thanks in advance,
Simon.