Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check record existence using Dynamic SQL
Message
 
To
29/07/2007 13:39:51
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01244442
Message ID:
01244443
Views:
16
This message has been marked as a message which has helped to the initial question of the thread.
>Hi,
>In my trigger, I use dynamic sql to check for record existence in other table before do actual update.
>
>Currently, I am using @@ROWCOUNT to check rows after run the dynamic SQL using EXEC(). However, it affect RecordsAffected property in ADO.NET. I also tried to use "SELECT @row_count = COUNT(*) ... ", but it hit error, seem like @row_count in not accessible in dynamic sql scope.
>
>Any workaround?
>
>Thank you

Maybe there is better solution that using dynamic SQL, but nobody could tell you when we didn't know your code.
try this:
........
CREATE TABLE #test (nCont int)

--your DynamicSQL
  'INSERT INTO #test
   SELECT COUNT(*) ........'
EXEC (.....)

DECLARE @row_count
SELECT @row_count = #Test.nCount FROM #Test
DROP TABLE #Test
.....
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform