How can I get number of deleted records?

That should work fine. The setting of NOCOUNT is irrelevant. This only affects the n rows affected information sent back to the client and has no effect on the workings of @@ROWCOUNT. Do you have any statements between the two that you have shown? @@ROWCOUNT is reset after every statement so you must retrieve the … Read more

How to solve “Batch update returned unexpected row count from update; actual row count: 0; expected: 1” problem?

The error means that the SQL INSERT statement is being executed, but the ROWCOUNT being returned by SQL Server after it runs is 0, not 1 as expected. There are several causes, from incorrect mappings, to UPDATE/INSERT triggers that have rowcount turned off. Your best beat is to profile the SQL statements and see what … Read more

How do you get all ancestors of a node using SQL Server 2008 hierarchyid?

The most commonly used approach would be a recursive Common Table Expression (CTE) WITH Ancestors(Id, [Name], AncestorId) AS ( SELECT Id, [Name], Id.GetAncestor(1) FROM dbo.HierarchyTable WHERE Name=”Joe Blow” — or whatever you need to select that node UNION ALL SELECT ht.Id, ht.[Name], ht.Id.GetAncestor(1) FROM dbo.HierarchyTable ht INNER JOIN Ancestors a ON ht.Id = a.AncestorId ) … Read more