I want get the value from Exec(@sql)
and assign to @Rowcount(int)
Here is my query:
'SET @RowCount = (select count(*)
FROM dbo.Comm_Services
WHERE CompanyId = '+cast(@CompanyId as char)+' and '+@condition+')'
6条答案
按热度按时间bsxbgnwa1#
On the one hand you could use sp_executesql:
On the other hand you could use a temporary table:
s6fujrry2#
5gfr0r5j3#
Was playing with this today... I believe you can also use
@@ROWCOUNT
, like this:Then replace the
SELECT 1 UNION SELECT 2
with your actual select without the count. I'd suggest just putting 1 in your select, like this:(as opposed to putting SELECT *)
Hope that helps.
b1zrtrql4#
that's my procedure
klsxnrf15#
With this pattern, you can return whatever type or results you are after from the results of your exec statement.
wa7juj8i6#
If i understand you correctly, (i probably don't)