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
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 theorder by:… and you can’t use the
casethat Gordon had directly in theorder bybecause it isn’t a selected value – you’ll get an ORA-07185. (Note that the column names in theorder byare the aliases that you assigned in theselect, not those in the table; and you don’t include the table name/alias; and it isn’t necessary to alias thenullcolumns in the union part, but you may want to for clarity).But this relies on
nullbeing 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 realeventkeycan ever benullanyway. 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: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 usetrunkinstead: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:
The
+ 1adds a day, so idDATE2was07/12/2012, the filter is< 2012-07-13 00:00:00, which is the same as<= 2012-07-12 23:59:59.