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 8560155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:12:49+00:00 2026-06-11T16:12:49+00:00

I have inherited the following statement: SELECT ISNULL((SELECT (-1)*SUM(CAST(ISNULL(NULLIF(TOTALMTDLCY,”),0) AS DECIMAL(20,5))) FROM TI),0) and

  • 0

I have inherited the following statement:

SELECT ISNULL((SELECT (-1)*SUM(CAST(ISNULL(NULLIF(TOTALMTDLCY,''),0) AS DECIMAL(20,5))) 
FROM TI),0) 

and although I know what it’s trying to do (prevent null values and return 0) I feel there must be a more performant way of doing this?

The reason is that I have a sproc that uses this statement 12 times to get values from different tables, for 40,000 customers (480,000) and then inserts three records for each (1.5M).

This takes around 13 mins to complete – and by gathering some simple stats on the process and totalling them it shows that although the actual time taken for the 12 statements is 00:00.015, the total time is therefore approx 10 mins.

So, my thinking is that if I can speed up this process, then I can speed up my sproc?

  • 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-06-11T16:12:50+00:00Added an answer on June 11, 2026 at 4:12 pm

    You should not use a varchar to store a numeric value, it will only cause you grief
    . Casting all values from varchar to decimal is costly.

    Change your table like

    update TI set TOTALMTDLCY = null where TOTALMTDLCY = ''
    alter table TI alter column TOTALMTDLCY DECIMAL(20,5) null
    

    Now you can select with no problems

    select isnull(-sum(TOTALMTDLCY), 0) from TI
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code (inherited from someone): <div class=feedback>&nbsp;</div> <form onsubmit=return false autocomplete=off>
I have the following select statement that I am using as a standard report:
I have the following query SELECT * FROM( SELECT CASE WHEN TO_CHAR (ADD_MONTHS(:DATEINPUT, 1),
Code which I have inherited keeps crashing out rather powerfully with the following error
I have the following code in specman that I inherited: some_method() is { var
I have defined an Event class: Event and all the following classes inherit from
I have the following dependency property in my MainWindow class (inherits from WPF's Window)
I have the following two classes, one inherits from the other Class A{ void
I have the following query; classB inherits from classA classC is friend of classB
Let's say I have the following class hierarchy: TaskViewer inherits from ListViewer<Task> which in

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.