<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Need to retrieve number of rows affected by SQL query in Product Lifecycle Management Q&amp;A</title>
    <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068148#M34026</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using separate Query template for @@ROWCOUNT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Put it as the last statement in the same Query after the update statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adarsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Jul 2010 07:38:42 GMT</pubDate>
    <dc:creator>sidnooradarsh</dc:creator>
    <dc:date>2010-07-08T07:38:42Z</dc:date>
    <item>
      <title>Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaq-p/7068146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am executing some update queries in SQL in a xMII transaction. Iam using a SQL Query template for the same and I need to find out how many records were affected by the last executed statement. I have tried doing SELECT @@ROWCOUNT in a second SQL template that executes after the UPDATE SQL Query Template. However, the results are intermittent, sometimes it returns 1 row affected as expected but sometimes returns 0 rows. Can anyone help on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 07:31:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaq-p/7068146</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T07:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068147#M34025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try using TRIGGER in another table where number of Audits will be inserted on time of execution of Update of the desired table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Som&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 07:38:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068147#M34025</guid>
      <dc:creator>former_member201407</dc:creator>
      <dc:date>2010-07-08T07:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068148#M34026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using separate Query template for @@ROWCOUNT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Put it as the last statement in the same Query after the update statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adarsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 07:38:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068148#M34026</guid>
      <dc:creator>sidnooradarsh</dc:creator>
      <dc:date>2010-07-08T07:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068149#M34027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Som,&lt;/P&gt;&lt;P&gt;I do not have any control over the database end, hence cannot create new tables/triggers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Adarsh,&lt;/P&gt;&lt;P&gt;I tried adding the @@Rowcount query at the end of the update statement.&lt;/P&gt;&lt;P&gt;E.g. I modified my query from Update mytable set col1='Some value' where col2=1234 &lt;/P&gt;&lt;P&gt;Update mytable set col1='Some value' where col2=1234 &lt;/P&gt;&lt;P&gt;to &lt;/P&gt;&lt;P&gt;Update mytable set col1='Some value' where col2=1234 ; Select @@RowCount&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this doesnt return any useful message. It simply returns Command Query Successful and not the count of rows affected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 08:04:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068149#M34027</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T08:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068150#M34028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't need to have control over DB end or go into the same, instead you can create table/trigger from MII end using the mode = Command in SQL Query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Som&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 08:08:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068150#M34028</guid>
      <dc:creator>former_member201407</dc:creator>
      <dc:date>2010-07-08T08:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068151#M34029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, my point is I do not have authorisation to modify table structures or create new ones. I understand this option might work for me, but it involves table/triggger creation. Is there any other way to resolve this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 08:23:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068151#M34029</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T08:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068152#M34030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anamika,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) As per sql best practices use of trigger is not recommend unless you don't have any other option because usually triggers consume more resources and IO since it involves internal monitoring.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) @@ROWCOUNT should go in same SQL session where you are performing update to identify rows affected else as you said earlier your results will not be accurate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) The other alternative is to create a Stored Procedure but it again boils down to your authorization issue. This would be easier and better if you have authorization to create SP's. But nevertheless give it a try.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) Lets forget about SP say that you have an Update Statement like&lt;/P&gt;&lt;P&gt;   &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Update Table1 set column2 = 'abc' where Column2 = 'xyz'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this case it is evident that you know what you are passing into the Where clause and to what table hence its obvious that you also know how many rows will be affected by using query, &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; Select count(*) from Table1 where Column2 = 'abc' &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The @@ROWCOUNT is powerful within t-sql with SP, cursors etc..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Hope this helps!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adarsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 09:13:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068152#M34030</guid>
      <dc:creator>sidnooradarsh</dc:creator>
      <dc:date>2010-07-08T09:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068153#M34031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Adarsh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since @@ROWCOUNT doesnt work for me, Iam now using SELECT COUNT(col1) ... approach.. This has resolved the problem iam facing. But its still a mystery for me why @@ROWCOUNT doesnt work sometimes..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 09:35:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068153#M34031</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T09:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068154#M34032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad your problem got solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@@ROWCOUNT will not work because when you put @@ROWCOUNT in different Query Template the @@ROWCOUNT  doesn't know which table was updated/inserted and it will show you the last/latest affected operation which could be anything other than your update statement hence its inaccurate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you place your @@ROWCOUNT immediately after any update/insert then it is nothing but putting all statements within a single transaction or single user session which should definitely give you results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do a small test in sql analyzer you will get to know &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good Luck!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Adarsh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 09:47:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068154#M34032</guid>
      <dc:creator>sidnooradarsh</dc:creator>
      <dc:date>2010-07-08T09:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068155#M34033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks..I know it works in SQL analyzer..but bad part is XMII doesnt support such things..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 10:30:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068155#M34033</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T10:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068156#M34034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using an alias for the column:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT @@ROWCOUNT AS NumRows.....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 12:41:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068156#M34034</guid>
      <dc:creator>jcgood25</dc:creator>
      <dc:date>2010-07-08T12:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need to retrieve number of rows affected by SQL query</title>
      <link>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068157#M34035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;U can try using OUTPUT clause along with your update query within Query template itself.&lt;/P&gt;&lt;P&gt;You can refer this link for more details on OUTPUT clause &lt;/P&gt;&lt;P&gt;&lt;A href="http://technet.microsoft.com/en-us/library/ms177564.aspx" target="test_blank"&gt;http://technet.microsoft.com/en-us/library/ms177564.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Your query mode should be set to Query and not Command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shalaka&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 12:50:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/product-lifecycle-management-q-a/need-to-retrieve-number-of-rows-affected-by-sql-query/qaa-p/7068157#M34035</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-08T12:50:26Z</dc:date>
    </item>
  </channel>
</rss>

