locked
Query RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I want if query return records using Stored procedure then perform some calculation else perform some other calculation

    Thanks

    Wednesday, November 14, 2018 5:26 AM

Answers

  • User753101303 posted

    Hi,

    What do you get from your SP ? You could use maybe : https://docs.microsoft.com/en-us/sql/t-sql/functions/rowcount-transact-sql?view=sql-server-2017

    --CREATE PROCEDURE sp_test AS SELECT 1 WHERE RAND()>=0.5
    GO
    EXEC sp_test
    IF @@ROWCOUNT=0 PRINT 'DO SOMETHING' ELSE PRINT 'SOMETHING ELSE'
    GO
    

    It sill returns the resultset. If it returns many rows I would change or would create another SP. Sometimes especially if unexperienced with Transact SQL, it's best to give more détails about the actual need so that one can suggest what could be done when starting from 0.

    Here this is a minimal amount assuming for example you can't change the SP at all and need to reuse it (and you don't need what it returns ?)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 14, 2018 9:41 AM