Search code examples
t-sqlsap-ase

Sybase ASE run query from one DB on the other


I have 2 databases DB and DB_ARCHIVE.

My SPROC archives (inserts records from DB into DB_ARCHIVE) records.
My SPROC resides in DB, but inside the SPROC I need to run a count on the records in the tables in DB_ARCHIVE

This is where my issue arises. I can run:

SELECT ROW_COUNT(DB_ID(), OBJECT_ID("DB.dbo.TABLE_NAME"))

in DB to get the row counts, but if I do:

SELECT ROW_COUNT(DB_ID(), OBJECT_ID("DB_ARCHIVE.dbo.TABLE_NAME"))

I only get a row count of 0 (fails).

Would someone know how I could run this query command in the SPROC on the DB_ARCHIVE database?


Solution

  • You should set the right database_id.
    Try this:

    SELECT ROW_COUNT(DB_ID("DB_ARCHIVE"), OBJECT_ID("DB_ARCHIVE.dbo.TABLE_NAME"))