<?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: rowcnt cross-database in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509499#M4950554</link>
    <description>Hi Mark, thanks for your interest. It didn’t work for me, but reading your comments gave me the idea about the stored procedure. By the way, I can’t post a comment below your latest one – I don’t know how to do it, so I have to do it here. Do you know how to post a comment below your latest one? I can’t see the ‘Comment’ option.</description>
    <pubDate>Thu, 22 Oct 2026 17:30:37 GMT</pubDate>
    <dc:creator>fjdelalamo</dc:creator>
    <dc:date>2026-10-22T17:30:37Z</dc:date>
    <item>
      <title>rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaq-p/14507316</link>
      <description>&lt;P&gt;Good morning,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have two databases, A and B, hosted on the same ASE server. While connected to database A, I need to retrieve the value of rowcnt(doampg) for a table in database B.&lt;/P&gt;&lt;P&gt;For example, I have tried the following query:&lt;/P&gt;&lt;P&gt;SELECT rowcnt(doampg)&lt;BR /&gt;FROM B..sysindexes&lt;BR /&gt;WHERE id = object_id("B..table_name")&lt;BR /&gt;&amp;nbsp; AND indid = 0&lt;/P&gt;&lt;P&gt;However, the result is always 0 when I execute this query from database A. If I switch my current database context to B and execute the equivalent query there, I get the expected information.&lt;BR /&gt;&lt;BR /&gt;Is there a way to retrieve the correct value for a table in database B while remaining in database A, without having to switch the current database context? More specifically, is there an alternative approach that does not require querying systabstats after executing flushstats?&lt;/P&gt;&lt;P&gt;I'm having this problem in ASE 12.5.x, but in later versions, "rowcnt" no longer exists and "row_count" is used instead; perhaps my problem was one of the reasons for the change.&lt;/P&gt;&lt;P&gt;Thank you very much for your time and help. This is an important issue for me, so any technical explanation, documentation references, or suggestions for further testing would be extremely valuable.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards and thanks in advanced&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2026 07:34:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaq-p/14507316</guid>
      <dc:creator>fjdelalamo</dc:creator>
      <dc:date>2026-10-22T07:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508726#M4950497</link>
      <description>&lt;P&gt;The&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;rowcnt()&lt;/EM&gt;&lt;/STRONG&gt; function was deprecated with the introduction of &lt;EM&gt;ASE 15.0&lt;/EM&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Could you update the question with the complete output from the query: &lt;EM&gt;&lt;STRONG&gt;select @@version&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2026 19:59:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508726#M4950497</guid>
      <dc:creator>Mark_A_Parsons</dc:creator>
      <dc:date>2026-10-21T19:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508749#M4950499</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Since the &lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;rowcnt()&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt; function was deprecated with the introduction of &lt;/SPAN&gt;&lt;EM&gt;ASE 15.0&lt;/EM&gt;&lt;SPAN&gt; I'm going to assume OP is running&lt;/SPAN&gt;&lt;EM&gt; ASE 12.x&lt;/EM&gt;&lt;SPAN&gt; in which case I'd suggest a&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;global stored procedure&lt;/STRONG&gt; (&lt;SPAN&gt;defined in the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;sybsystemprocs&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt; database with a name that starts with '&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;sp_&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;' - though I'd suggest '&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;sp__&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;' to distinguish from system stored procedures).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;---------------------&lt;/P&gt;&lt;P&gt;For demo purposes I've created&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;MyObject&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;(&lt;EM&gt;table&lt;/EM&gt;&amp;nbsp;in &lt;EM&gt;&lt;STRONG&gt;db1&lt;/STRONG&gt;&lt;/EM&gt;; procedure in &lt;EM&gt;&lt;STRONG&gt;db2&lt;/STRONG&gt;&lt;/EM&gt;) :&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;use db1
go

create table MyObject
(a    int     null
,b    int     null
)
go

use db2
go

create procedure MyObject
as
    print 'hi'
go&lt;/LI-CODE&gt;&lt;P&gt;Running the following query in both databases to obtain details on &lt;EM&gt;&lt;STRONG&gt;MyObject&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;select  db_name() as 'database',name as 'object name',id,type
from    sysobjects
where   id = object_id('MyObject')
go

-- results reformatted for readability

 database object name id         type
 -------- ----------- ---------- ----
 db1      MyObject    1657105963 U
 db2      MyObject    1408005016 P&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;We'll incorporate this same code in a global procedure (&lt;EM&gt;&lt;STRONG&gt;sp__help&lt;/STRONG&gt;&lt;/EM&gt;) we'll place in the &lt;STRONG&gt;&lt;EM&gt;sybsystemprocs&lt;/EM&gt;&lt;/STRONG&gt; database :&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;use sybsystemprocs
go

create procedure sp__help
@objname varchar(255) ='sysobject'
as
    select  db_name() as 'database',name as 'object name',id,type
    from    sysobjects
    where   id = object_id(@objname)
go&lt;/LI-CODE&gt;&lt;P&gt;For demo purposes we'll make our calls to &lt;EM&gt;&lt;STRONG&gt;sp__help&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;from the &lt;EM&gt;&lt;STRONG&gt;master&lt;/STRONG&gt;&lt;/EM&gt; database :&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;use master
go

exec db1..sp__help 'MyObject'
exec db2..sp__help 'dbo.MyObject'
go

 database object name      id         type 
 -------- ---------------- ---------- ---- 
 db1      MyObject         1657105963 U    

 database object name      id         type 
 -------- ---------------- ---------- ---- 
 db2      MyObject         1408005016 P    &lt;/LI-CODE&gt;&lt;P&gt;Notice that we use the database name (&lt;EM&gt;&lt;STRONG&gt;db1&lt;/STRONG&gt;&lt;/EM&gt;, &lt;EM&gt;&lt;STRONG&gt;db2)&lt;/STRONG&gt;&lt;/EM&gt; to fully qualify the stored proc name (as opposed to fully qualifying the object name as in OP's sample query).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTES&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;while the above code was tested on an &lt;EM&gt;ASE 16.0 SP04 PL04&lt;/EM&gt; instance, I would expect it to also work on&amp;nbsp;&lt;EM&gt;ASE 12.x&lt;/EM&gt; (see separate answer demonstrating a &lt;STRONG&gt;global stored procedure&lt;/STRONG&gt; running OP's &lt;STRONG&gt;&lt;EM&gt;rowcnt()&lt;/EM&gt;&lt;/STRONG&gt; query against an &lt;EM&gt;ASE 12.5.4&lt;/EM&gt; instance)&lt;/LI&gt;&lt;LI&gt;if there's a requirement to capture the global procedure's output for further T-SQL processing (eg, capture the row count result from OP's query), the global procedure can be modified to include output parameters [I'll leave this for OP to test]&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 27 Oct 2026 16:59:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508749#M4950499</guid>
      <dc:creator>Mark_A_Parsons</dc:creator>
      <dc:date>2026-10-27T16:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508842#M4950503</link>
      <description>&lt;P&gt;NB: I was curious about rowcnt, here are the URLs to the documentation; rowcnt in ASE 12.5.1 -&amp;gt; row_count in ASE 15.5 as shown in Reference Manual: Building Blocks &amp;gt; Transact-SQL Functions.&lt;/P&gt;&lt;P&gt;12.5.1:&amp;nbsp;&lt;A href="https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36271_1251/html/blocks/X91424.htm" target="_blank" rel="noopener"&gt;https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36271_1251/html/blocks/X91424.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;15.0 (archive in PDF format): &lt;A href="https://infocenter-archive.sybase.com/help/topic/com.sybase.help.ase_15.0.aserbwin/aserbwin.pdf" target="_self"&gt;Release Bulletin Adaptive Server® Enterprise Version 15.0 &amp;gt; 7. Changes that may affect existing applications &amp;gt; 7.3 Changes that affect database administration operations &amp;gt; 7.3.1 Usage of system built-ins&lt;/A&gt;: &lt;EM&gt;"Built-in functions that provide space information like data_pgs, reserved_pgs, used_pgs, ptn_data_pgs and rowcnt have been deprecated. They have been replaced with data_pages, reserved_pages, used_pages, and row_count."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;15.5:&amp;nbsp;&lt;A href="https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36271_1251/html/blocks/X91424.htm" target="_blank" rel="noopener"&gt;https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36271_1251/html/blocks/X91424.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;16.0:&amp;nbsp;&lt;A href="https://help.sap.com/docs/SAP_ASE/2df920cd5b1644e5a065d55b637d5e92/aae06819bc2b1014af108fd1a517367e.html?locale=en-US" target="_blank" rel="noopener"&gt;https://help.sap.com/docs/SAP_ASE/2df920cd5b1644e5a065d55b637d5e92/aae06819bc2b1014af108fd1a517367e.html?locale=en-US&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sandra_Rossi_0-1792641955461.png" style="width: 999px;"&gt;&lt;img src="https://community.sap.com/t5/image/serverpage/image-id/471763i0A238E268C2A83A7/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="Sandra_Rossi_0-1792641955461.png" alt="Sandra_Rossi_0-1792641955461.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Sandra&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2026 04:15:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14508842#M4950503</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2026-10-22T04:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509055#M4950517</link>
      <description>Hi Mark, first of all, thank you for replying and for wanting to help. Let me explain: in 12.5.x, I’ve tried what you suggested and have opted for a compromise solution – creating a stored procedure in both databases as follows: CREATE PROC test @table VARCHAR(255) AS SELECT ROWCNT(doampg) FROM sysindexes WHERE id = OBJECT_ID(@table) AND indid = 0 Then I simply run `database..test &amp;lt;table name&amp;gt;` and I get the result. I don’t like creating objects for this purpose, but it’s a good workaround.</description>
      <pubDate>Thu, 22 Oct 2026 09:02:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509055#M4950517</guid>
      <dc:creator>fjdelalamo</dc:creator>
      <dc:date>2026-10-22T09:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509058#M4950518</link>
      <description>Hi Mark, first of all, thank you for replying and for wanting to help.</description>
      <pubDate>Thu, 22 Oct 2026 09:06:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509058#M4950518</guid>
      <dc:creator>fjdelalamo</dc:creator>
      <dc:date>2026-10-22T09:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509068#M4950520</link>
      <description>&lt;P&gt;Hi, Mark: first of all, thank you for replying and for wanting to help me.&lt;/P&gt;&lt;P&gt;I don’t know how to thank you for each comment individually, so I’m replying with this message. Let me explain: in version 12.5.x, I’ve tried what you suggested and have opted for a compromise: creating a stored procedure in both databases as follows:&lt;/P&gt;&lt;P&gt;CREATE PROC test&lt;BR /&gt;@table VARCHAR (255)&lt;BR /&gt;AS&lt;BR /&gt;SELECT ROWCNT(doampg)&lt;BR /&gt;FROM sysindexes&lt;BR /&gt;WHERE id = OBJECT_ID(@table)&lt;BR /&gt;AND indid = 0&lt;/P&gt;&lt;P&gt;I then simply run `database..test &amp;lt;table name&amp;gt;` and get the result. I don’t like creating objects for this purpose, but given that I cannot run a cross-database query for this, it’s a good workaround.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2026 09:13:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509068#M4950520</guid>
      <dc:creator>fjdelalamo</dc:creator>
      <dc:date>2026-10-22T09:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509484#M4950553</link>
      <description>&lt;P&gt;Ah, yes, this solution (&lt;EM&gt;local proc in each database&lt;/EM&gt;) works, too! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Whenever I see a requirement to run a proc in multiple databases I automatically think &lt;EM&gt;&lt;STRONG&gt;global stored proc&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;(a habit formed over a couple decades) so I sometimes forget the &lt;A href="https://medium.com/@Masoncoding/understanding-the-kiss-principle-in-software-design-keep-it-simple-stupid-6f5fcd8913f3" target="_self"&gt;KISS principal&lt;/A&gt; (eg, separate proc in each database). Having said that ...&lt;/P&gt;&lt;P&gt;I don't currently have access to an &lt;EM&gt;ASE 12.5.x&lt;/EM&gt; instance so I'm curious to know: Did you try creating a &lt;EM&gt;&lt;STRONG&gt;global stored proc&lt;/STRONG&gt;&lt;/EM&gt; in &lt;EM&gt;ASE 12.5.x&lt;/EM&gt; and if so, did you have any issues?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2026 17:13:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509484#M4950553</guid>
      <dc:creator>Mark_A_Parsons</dc:creator>
      <dc:date>2026-10-22T17:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509499#M4950554</link>
      <description>Hi Mark, thanks for your interest. It didn’t work for me, but reading your comments gave me the idea about the stored procedure. By the way, I can’t post a comment below your latest one – I don’t know how to do it, so I have to do it here. Do you know how to post a comment below your latest one? I can’t see the ‘Comment’ option.</description>
      <pubDate>Thu, 22 Oct 2026 17:30:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509499#M4950554</guid>
      <dc:creator>fjdelalamo</dc:creator>
      <dc:date>2026-10-22T17:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509916#M4950605</link>
      <description>Instead of commenting on comments, you comment on the associated answer. Unlike other website discussion/forum systems that can support nested comments, this (SAP) system has the single level of comments associated with an answer.</description>
      <pubDate>Fri, 23 Oct 2026 13:52:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14509916#M4950605</guid>
      <dc:creator>Mark_A_Parsons</dc:creator>
      <dc:date>2026-10-23T13:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: rowcnt cross-database</title>
      <link>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14511844#M4950719</link>
      <description>&lt;P&gt;Finally found an &lt;EM&gt;ASE 12.5.4&lt;/EM&gt; instance (supports the &lt;EM&gt;&lt;STRONG&gt;rowcnt()&lt;/STRONG&gt;&lt;/EM&gt; function) so I can demonstrate a &lt;STRONG&gt;global stored procedure&lt;/STRONG&gt;&amp;nbsp;running OP's &lt;EM&gt;&lt;STRONG&gt;rowcnt()&lt;/STRONG&gt;&lt;/EM&gt; query ...&lt;/P&gt;&lt;P&gt;Setup:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;-- create table in both databases (db1, db2)

create table tab1 (a int, b varchar(100))
go

-- leave the table empty in db1; populate the table in db2

insert tab1 select id,'stuff' from sybsystemprocs..sysobjects
go

-- run a modified copy of OP's query in both databases;
-- results are reformatted for readability

select  db_name() as 'db', object_name(id) as 'table', rowcnt(doampg) as 'rowcnt'
from    sysindexes
where   id = object_id('tab1')
and     indid = 0
go

 db  table rowcnt
 --- ----- ------
 db1 tab1       0
 db2 tab1     477&lt;/LI-CODE&gt;&lt;P&gt;Wrapping the modified query in a stored procedure wrapper and installing in the &lt;STRONG&gt;&lt;EM&gt;sybsystemprocs&lt;/EM&gt;&lt;/STRONG&gt; database:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;use sybsystemprocs
go

create procedure sp__rowcnt
@objname varchar(255) ='sysobject'
as

select  db_name() as 'db', object_name(id) as 'table', rowcnt(doampg) as 'rowcnt'
from    sysindexes
where   id = object_id(@objname)
and     indid = 0
go&lt;/LI-CODE&gt;&lt;P&gt;From the &lt;EM&gt;&lt;STRONG&gt;master&lt;/STRONG&gt;&lt;/EM&gt; database we'll run &lt;EM&gt;&lt;STRONG&gt;sp__rowcnt&lt;/STRONG&gt;&lt;/EM&gt; against the two tables:&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;use master
go

exec db1..sp__rowcnt 'tab1'
exec db2..sp__rowcnt 'dbo.tab1'
go

 db  table rowcnt
 --- ----- ------
 db1 tab1       0

 db  table rowcnt
 --- ----- ------
 db2 tab1     477&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2026 16:55:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/rowcnt-cross-database/qaa-p/14511844#M4950719</guid>
      <dc:creator>Mark_A_Parsons</dc:creator>
      <dc:date>2026-10-27T16:55:36Z</dc:date>
    </item>
  </channel>
</rss>

