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

  • Home
  • SEARCH
  • 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 9253733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:17:36+00:00 2026-06-18T11:17:36+00:00

I need a query that bring me a table like 7 AM | 7:30

  • 0

I need a query that bring me a table like

7 AM | 7:30 AM | 8 AM   | 8:30 AM...........|6:30 PM|
----- --------- -------- ----- ............. -------
     | Booked  | Booked | Booked ...........|       |

My Table Name is : zUSM_RoomReservationInfo
This is the structure and Data of the Table

ReservationID RoomId  StartDateTime           EndDateTime             
------------- ------- ----------------------- ----------------------- 
1             102     2013-02-01 10:00:00.000 2013-02-01 12:00:00.000 
2             201     2013-01-27 16:00:00.000 2013-01-27 17:00:00.000 
3             102     2013-02-01 14:00:00.000 2013-02-01 16:00:00.000   

By Giving ONE Date and Room Id as Input it should give me table like I mentioned above.

  • 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-18T11:17:37+00:00Added an answer on June 18, 2026 at 11:17 am

    Please try:

    DECLARE @RoomID NVARCHAR(10), @DtParam NVARCHAR(20), @dt1 DATETIME, @dt2 DATETIME, @Col NVARCHAR(MAX), @Query NVARCHAR(MAX)
    select @RoomID='102', @DtParam='01-Feb-2013', @dt1='07:00', @dt2='17:00', @Col='', @Query=''
    
    CREATE TABLE #table (DT DATETIME)
    
    while @dt1<=@dt2
    begin
        SET @Col=@Col+'['+CONVERT(CHAR(5), @dt1, 108)+'],'
        insert into #table values (@dt1)
        SET @dt1=dateadd(minute, 30, @dt1)
    end
    
    select @Col=LEFT(@Col, LEN(@Col) -1)
    
    set @Query='select '+@Col+' From(
    select DT, ReservationID From #table t1 left outer join (select * from zUSM_RoomReservationInfo
    where RoomID='+@RoomID+' AND DATEADD(dd, 0, DATEDIFF(dd, 0, StartDateTime))=CONVERT(DATETIME, '''+@DtParam+'''))t2 on t1.DT
    between CONVERT(CHAR(5), StartDateTime, 108) and CONVERT(CHAR(5), EndDateTime, 108)
    
    )x pivot (count(ReservationID) for DT IN ('+  @Col+'))PIV'
    exec (@Query)
    
    drop table #table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a query that will return a table where each column is the
I need a SQLite query that searches 1 field only using LIKE. Basic example:
I need to write a query that will go through a table, find duplicate
I've got a sub-select in a query that looks something like this: left outer
Exactly like my title states i need a query that removes the first chracter
I have 3 tables. Table A contains the data that my query is going
I have a table like this: | X | Y | Data | ----------------
I have a table that looks like this: ID StartRange EndRange ---------------------------- 1 1
I have a table of results that looks like this: score_id, uid, af_id, level,
Database has tables Photos and PhotoAlbums. I need a query that will select all

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.