Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:17:38+00:00 2026-05-23T04:17:38+00:00

How would you implement that check? You have N parameters for a stored procedure.

  • 0

How would you implement that check? You have N parameters for a stored procedure.

If all value are null or 0 or empty string, run the code else skip it

This is how I implemented it, is there a better way?

I really don’t like what I did so I’m open to any better idea, must be easily maintainable since it would be done at many places

    declare @doRunIt bit
    declare @checkAllNull varchar(max)
    declare @sumOfInt int

    set @checkAllNull = ''
    set @checkAllNull = @checkAllNull + coalesce(@param1,'')
    set @checkAllNull = @checkAllNull + coalesce(@param2,'')
    set @checkAllNull = @checkAllNull + coalesce(@param3,'')
    set @checkAllNull = @checkAllNull + coalesce(@param4,'')
    set @checkAllNull = @checkAllNull + coalesce(@param5,'')
    set @checkAllNull = @checkAllNull + coalesce(@param6,'')

    set @sumOfInt = coalesce(@param7,0)+coalesce(@param8,0)+
                    coalesce(@param9,0)+coalesce(@param10,0)+
                    coalesce(@param11,0)+coalesce(@param12,0)

    set @checkAllNull = @checkAllNull + cast(@sumOfInt as varchar(max))



    if ( isnumeric(@checkAllNull)=1 )
        if (cast(@checkAllNull as int) > 0)
            set @doRunIt = 1
        else
            set @doRunIt = 0
    else
        if (ltrim(rtrim(@checkAllNull)) <> '')
            set @doRunIt = 1
        else
            set @doRunIt = 0

End goal is to move the check made in code for inserting empty row, if all parameters are null or using default value, in the DB into the stored procedure, so other apps can call the same stored procedure without having to deal with checking for empty row.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:17:39+00:00Added an answer on May 23, 2026 at 4:17 am

    Your code

    DECLARE @IsValid BIT = dbo.IsValidParameter(@param1) & 
                           dbo.IsValidParameter(@param2) & 
                           dbo.IsValidParameter(@param3) & 
                           dbo.IsValidParameter(@param4)
    

    Helper function

    CREATE FUNCTION dbo.IsValidParameter(@p1 Sql_Variant)
    RETURNS bit
    AS
    BEGIN
        IF @p1 IS NULL OR @p1 = '' OR @p1 = 0
            RETURN 0    
        RETURN 1    
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the code below, how would you create/implement SR.h so that it produces the
I have several templated objects that all implement the same interface: I.E. MyObject<datatype1> obj1;
I have code that I would like to convert so that I am grabbing
I would like to implement operations that is undoable in a short time after
I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
I would like to implement a post build event that performs the following actions
We would like to implement a web form that automatically saves content at regular
I would like to implement or use functionality that allows stepping through a Table
I would like to implement an input mask on Magento and that requires the
i would like to implement 'drawing modes' (in my own graphics library). That is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.