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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:22:09+00:00 2026-05-11T12:22:09+00:00

I have a TSQL SELECT that can return a null. I tried using ISNULL

  • 0

I have a TSQL SELECT that can return a null. I tried using ISNULL to replace it with 0 but for some reason it is not working. The table selecting from has the following columns:

  • storeID –> int
  • penaltyPercent –> decimal(9,2)
  • penaltyDate –> dateTime
SELECT  ISNULL(penaltyPercent, 0.0) AS penaltyPercent   FROM    dbo.Penalty   WHERE   (penaltyDate = (SELECT     MAX(penaltyDate) AS date                           FROM       dbo.Penalty AS Penalty_1                           WHERE      (penaltyDate <= @date) AND (storeID = @storeID))) AND         (storeID = @storeID)  

When the date is before the first penalty date (when there should be 0 penalty), no result is returned. Not sure why this doesn’t work. I have a work around but it is bugging me.

Here is a sample of the data being used:

storeID  penaltyDate             penaltyPercent   182      10/1/2008 12:00:00 AM   0.020000   182      11/1/2008 12:00:00 AM   0.040000   182      12/1/2008 12:00:00 AM   0.070000   
  • 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. 2026-05-11T12:22:10+00:00Added an answer on May 11, 2026 at 12:22 pm

    When you say ‘When the date is before the first penalty date’, do you mean when the value of @date is less than the value returned from this query?

    SELECT MIN(penaltyDate) FROM Penalty 

    Because then your inner query is going to return null, and (if you’re using ANSI nulls) this part will return false,

    WHERE (penaltyDate = ... 

    Because comparisons with null always return null. So instead of selecting one row with a null value, you’re selecting no rows.

    Addendum:

    To confirm this is the problem, change your outer query’s first line to

    SELECT ISNULL(MAX(penaltyPercent),0.0) AS penaltyPercent 

    It will work because of what I’ve described above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure if your concern is loading the DTD… May 12, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer First, var array=[]; is preferable to using "new." Second, your… May 12, 2026 at 12:27 am
  • Editorial Team
    Editorial Team added an answer I found the problem! g++ command problem! :( sorry. If… May 12, 2026 at 12:27 am

Related Questions

I'm using a SELECT statement in T-SQL on a table similar to this: SELECT
Can someone please identify the functional/performance differences, if any, between SET and SELECT in
Much of my application uses complied queries to retrieve data. In these queries I'll
I have two tables in the system. I'm trying to make a VIEW that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.