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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:47:19+00:00 2026-05-26T05:47:19+00:00

My SQL Query below is now Returning the RoomsAvailable field correctly except when theres

  • 0

My SQL Query below is now Returning the RoomsAvailable field correctly except when theres 0 rooms taken, in which the SQL command subtracts number_of_rooms with NULL and outputs NULL to the Column. I have tried numerous ISNULL variations and found that it doesnt work; anyone know how I should be doing this?

SQL :

SELECT
    Hotel_2.hotel_code, 
    Hotel_2.hotel_country, 
    Room_type_rates_2.room_type_code, 
    Room_type_rates_2.number_of_rooms, 
    Types_2.room_type, 
    Room_type_rates_2.rates, 
            Room_type_rates_2.number_of_rooms -
            (SELECT 
                DISTINCT (SELECT
                             COUNT(dbo.Hotel.hotel_code) AS RoomsTake
                          FROM
                              dbo.Hotel 
                          INNER JOIN dbo.Hotel_Reservation 
                              ON dbo.Hotel.hotel_code = dbo.Hotel_Reservation.hotel_code 
                          INNER JOIN dbo.Room_type_rates 
                              ON dbo.Hotel.hotel_code = dbo.Room_type_rates.hotel_code 
                          INNER JOIN dbo.Types 
                              ON dbo.Hotel_Reservation.room_type_code = dbo.Types.room_type_code 
                              AND dbo.Room_type_rates.room_type_code = dbo.Types.room_type_code
                          WHERE
                              (dbo.Room_type_rates.room_type_code = Room_type_rates_1.room_type_code) 
                              AND (dbo.Hotel.hotel_code = Hotel_1.hotel_code)
                              AND (dbo.Hotel_Reservation.checkin_date >= Hotel_Reservation_1.checkin_date)
                              AND (dbo.Hotel_Reservation.checkout_date <= Hotel_Reservation_1.checkout_date)
                          ) AS RoomsTaken
               FROM
                   dbo.Hotel AS Hotel_1 
               INNER JOIN dbo.Hotel_Reservation AS Hotel_Reservation_1
                   ON Hotel_1.hotel_code = Hotel_Reservation_1.hotel_code 
               INNER JOIN dbo.Room_type_rates AS Room_type_rates_1 
                   ON Hotel_1.hotel_code = Room_type_rates_1.hotel_code 
               INNER JOIN dbo.Types AS Types_1 
                   ON Hotel_Reservation_1.room_type_code = Types_1.room_type_code 
                   AND Room_type_rates_1.room_type_code = Types_1.room_type_code
               WHERE
                   (Hotel_Reservation_1.checkin_date >= '11/19/2011') 
                   AND (Hotel_Reservation_1.checkout_date <= '12/01/2011') 
                   AND (Hotel_1.hotel_country = 'Adelaide') 
                   AND (Types_1.room_type_code = Types_2.room_type_code)
               ) AS RoomsAvailable 
FROM 
    dbo.Hotel AS Hotel_2 
INNER JOIN dbo.Room_type_rates AS Room_type_rates_2 
    ON Hotel_2.hotel_code = Room_type_rates_2.hotel_code 
INNER JOIN dbo.Types AS Types_2 
    ON Room_type_rates_2.room_type_code = Types_2.room_type_code

Current Output :


ADL20 Adelaide CPL 6 Couple Suite 514.0000 3

ADL20   Adelaide    FYU         3   Family Suite    533.0000    2

ADL20   Adelaide    KNG         2   King's Bedroom  556.0000    NULL

  • 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-26T05:47:20+00:00Added an answer on May 26, 2026 at 5:47 am

    Do you mean this?:

    ...ISNULL(COUNT(dbo.Hotel.*),0)...
    

    Or is the problem that you’re getting NULL at all? In that case I would suspect your JOINs may have a problem.

    You can wrap an ISNULL around any nested subquery or value.

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

Sidebar

Related Questions

Consider the SQL query below: SELECT * FROM opening_hours WHERE week_day = WEEKDAY(NOW()) +
This might be a very simple thing. Check out the normal sql query below
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOGID
I am using SQL Query and below are the tables. Organization OrgID Name RAOID
Below SQL query works when the spaces in the role name are replaced by
I'm trying to convert the below SQL query to HQL and am having a
I have RO access on a SQL View. This query below times out. How
I'm reading a book about SQL. In that book, I saw strange query below:
I am having some problems turning the SQL below into a Zend Db query.

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.