0

With the below count queries I will like to have them all appear on one screen with a separator (-----------).

SELECT count(*) as Count_F3112 FROM PRODDTA.F3112; --> WO Routing
SELECT count(*) as Count_F4801 FROM PRODDTA.F4801; --> WO Header (Master File)
SELECT count(*) as Count_F0006 FROM PRODDTA.F0006; --> Business Unit Master
SELECT count(*) as Count_F0101 FROM PRODDTA.F0101; --> Address Book Master

SAMPLE

I executed the statements and the lines were separated into individual query results.

1
  • Whats the database type? SQL Server, Postgres, MySQL? Commented Dec 12, 2022 at 4:46

3 Answers 3

1

You could use a union query:

SELECT COUNT(*) AS cnt, 'WO Routing' AS label FROM PRODDTA.F3112
UNION ALL
SELECT COUNT(*), 'WO Header (Master File)' FROM PRODDTA.F4801
UNION ALL
SELECT COUNT(*), 'Business Unit Master' FROM PRODDTA.F0006
UNION ALL
SELECT COUNT(*), 'Address Book Master' FROM PRODDTA.F0101;
Sign up to request clarification or add additional context in comments.

Comments

0

user sparator from select only '-----'

SELECT count(*) as Count_F3112 FROM PRODDTA.F3112
    UNION ALL
    SELECT '-----------'
    UNION ALL
    SELECT count(*) as Count_F4801 FROM PRODDTA.F4801
    UNION ALL
    SELECT '-----------'
    UNION ALL
    SELECT count(*) as Count_F0006 FROM PRODDTA.F0006
    UNION ALL
    SELECT '-----------'
    SELECT count(*) as Count_F0101 FROM PRODDTA.F0101

2 Comments

depending on the database used this can error, because the columns are not the same type ('---' is string, but count(*) is numeric). Also the orde rof the results are not guaranteed
yes , you can use Cast first befor count, cast (count(*) as nvarchar)
0

You can use a UNION!

SELECT count(*) as Count_F3112 FROM PRODDTA.F3112 UNION
SELECT count(*) as Count_F4801 FROM PRODDTA.F4801 UNION
SELECT count(*) as Count_F0006 FROM PRODDTA.F0006 UNION
SELECT count(*) as Count_F0101 FROM PRODDTA.F0101; 

2 Comments

union can be risky if the counts from two separate tables have the same count; UNION ALL would be better, but the OP asks for a report anyway, not just 4 numbers
I've asked the OP to clarify the database type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.