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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:49:21+00:00 2026-06-07T13:49:21+00:00

I have SQL Query, I want to add insert blank row in result so

  • 0

I have SQL Query, I want to add insert blank row in result so it is easy to see the result.
I want to insert it after ORDER BY. don’t know if it could be done.

Here is my select statement.

SELECT TableName.CREWACTIONFACTID
      ,TableName.CREWKEY as CrewKey
      ,TableName.EVENTKEY as EventID
      ,TableName.ACTIONSEQUENCE
      ,case TableName.ACTIONTYPE
            when 'DISPATCHED' then '2-Dispatched'
            when 'ASSIGNED' then '1-Assigned'
            when 'ENROUTE' then '3-Entoute'
            when 'ARRIVED' then '4-Arrived'
            else 'unknown'
            end  as Type
      ,TableName.STARTDATETIME as StartTime
      ,TableName.ENDDATETIME as EndTIme
      ,TableName.DURATION as Duration

  FROM DatabaseName.TableName TableName
  where 
    To_Date(to_char(TableName.STARTDATETIME, 'DD-MON-YYYY')) >= To_Date('?DATE1::?','MM/DD/YYYY')
    AND To_Date(to_char(TableName.ENDDATETIME, 'DD-MON-YYYY')) <= To_Date('?DATE2::?','MM/DD/YYYY')
   ORDER BY TableName.EVENTKEY, TableName.STARTDATETIME,TableName.ACTIONSEQUENCE
  • 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-07T13:49:24+00:00Added an answer on June 7, 2026 at 1:49 pm

    You can, pretty much as Michael and Gordon did, just tack an empty row on with union all, but you need to have it before the order by:

    ...
    and to_date(to_char(t.enddatetime, 'DD-MON-YYYY')) <=
        to_date('?DATE2::?','MM/DD/YYYY')
    union all
    select null, null, null, null, null, null, null, null
    from dual
    order by eventid, starttime, actionsequence;
    

    … and you can’t use the case that Gordon had directly in the order by because it isn’t a selected value – you’ll get an ORA-07185. (Note that the column names in the order by are the aliases that you assigned in the select, not those in the table; and you don’t include the table name/alias; and it isn’t necessary to alias the null columns in the union part, but you may want to for clarity).

    But this relies on null being sorted after any real values, which may not always be the case (not sure, but might be affected by NLS parameters), and it isn’t known if the real eventkey can ever be null anyway. So it’s probably safer to introduce a dummy column in both parts of the query and use that for the ordering, but exclude it from the results by nesting the query:

    select crewactionfactid, crewkey, eventid, actionsequence, type,
        starttime, endtime, duration
    from (
        select 0 as dummy_order_field,
            t.crewactionfactid,
            t.crewkey,
            t.eventkey as eventid,
            t.actionsequence,
            case t.actiontype
                when 'DISPATCHED' then '2-Dispatched'
                when 'ASSIGNED' then '1-Assigned'
                when 'ENROUTE' then '3-Enroute'
                when 'ARRIVED' then '4-Arrived'
                else 'unknown'
            end as type,
            t.startdatetime as starttime,
            t.enddatetime as endtime,
            t.duration
        from schema_name.table_name t
        where to_date(to_char(t.startdatetime, 'DD-MON-YYYY')) >=
            to_date('?DATE1::?','MM/DD/YYYY')
        and to_date(to_char(t.enddatetime, 'DD-MON-YYYY')) <=
            to_date('?DATE2::?','MM/DD/YYYY')
        union all
        select 1, null, null, null, null, null, null, null, null
        from dual
    )
    order by dummy_order_field, eventid, starttime, action sequence;
    

    The date handling is odd though, particularly the to_date(to_char(...)) parts. It looks like you’re just trying to lose the time portion, in which case you can use trunk instead:

    where trunc(t.startdatetime) >= to_date('?DATE1::?','MM/DD/YYYY')
    and trunc(t.enddatetime) <= to_date('?DATE2::?','MM/DD/YYYY')
    

    But applying any function to the date column prevents any index on it being used, so it’s better to leave that alone and get the variable part in the right state for comparison:

    where t.startdatetime >= to_date('?DATE1::?','MM/DD/YYYY')
    and t.enddatetime < to_date('?DATE2::?','MM/DD/YYYY') + 1
    

    The + 1 adds a day, so id DATE2 was 07/12/2012, the filter is < 2012-07-13 00:00:00, which is the same as <= 2012-07-12 23:59:59.

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

Sidebar

Related Questions

I have the following sql query and I want to filter the results where
I have a DataGridView bound to a LINQ to SQL query expression. I want
I want make sql query which will insert values from one table to another
I have sql query in my asp.net webapp and the result is stored in
In php I have an INSERT query to database. This query add some issue
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
I have a SQL query (MS Access) and I need to add two columns,
When I add an aggregate function to the SQL query, I get a row
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
As I had written in title, I have SQL query, run on Oracle DB,

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.