Doubt in using UNION between queries

HI,
Here is my query,
SELECT
     NULL AS NAME,
     NULL AS VDATE,
     'SP' AS OBJECTS
FROM DUAL
UNION
SELECT
     'MURALI' AS NAME,
     SYSDATE AS VDATE,
     NULL
FROM DUAL;
The Result from the query is
NAME----VDATE---OBJECTS
MURALI-- 12/1/2007----
--- ---- SP
But i need the output as
NAME----VDATE---OBJECTS
MURALI-- 12/1/2007----0
0 --- 0 ---- SP
Can anyone help me in this ?

sql>
SELECT
'0' AS NAME,
'0' AS VDATE,
'SP' AS OBJECTS
FROM DUAL
UNION
SELECT
'MURALI' AS NAME,
to_char(SYSDATE) AS VDATE,
'0'
FROM DUAL
order by name desc;
NAME VDATE OB
MURALI  25/Jan/2007   0 
0       0             SP
jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to use 'UNION' between two different databaseservers

    Hello,
    Could someone help me out. I am trying to find out if and how to use 'UNION' between two different databaseservers.
    We have 2 different queries, each queries on a different database; one MySQL the other MSSQL.
    Could someone tell me how to use 'UNION' between thes 2 queries?
    Thanks in advance,
    Samir Benalla

    Hello
    You may use openrowset statement, (OPENROWSET (Transact-SQL))., but before you use this, you must configure your server
    sample:
    SELECT a.*
    FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',
         'SELECT GroupName, Name, DepartmentID
          FROM AdventureWorks2012.HumanResources.Department
          ORDER BY GroupName, Name') AS a
    UNION
         SELECT GroupName, Name, DepartmentID
          FROM AdventureWorks2012.HumanResources.Department
          ORDER BY GroupName, Name
    With this you can define a connection using native client to server Seattle1, and execute a query there, The results will be spooled on your server.
    Connectionstring
    Server=[SERVER_NAME];datasource=[YOUR DATABASE NAME];user_id=sa;password=sapassword'
    if you use FQDN on your Query, than the datasource parameter in connection string can be letf out.
    Regards
    János.
    take care of performance, it can be very slow,

  • Query takes long when using UNION

    Hi ,
    I habe a query as follows;
    SELECT
                        '9999' site_id,
                        m.ghi_prov_num provnum,
                           SUBSTR (l.seq_num, 1, 3)provloc,
                        t.dea_number dea,
                            t.license_number statelicensenumber ,
                            n.npi_num npi,
                            m.prefix prefixname,
                            m.lastname lastname,
                            m.firstname firstname,
                            t.middle_name middleinitial,
                            m.suffix suffixname,
                            null clinicname,
                            l.street1 addressline1,
                            l.street2 addressline2,
                            l.city city,
                            l.state state,
                            l.zip5 zip,
                            l.phone phoneprimary,
                            null ext,
                            null fax,
                            null email,
                            null alt_phone,
                            null alt_phone_ext
                     FROM provider m, LOCATION l, npi n,TEMP_VITAL_CACTUS t,test_provider_pin pin
                      WHERE m.ghi_prov_num=l.ghi_prov_num
                          and m.ghi_prov_num=n.ghi_prov_num(+)
                          and m.ghi_prov_num=t.ghi_prov_num(+)
                          and m.tax_id=pin.tax_id
         UNION
          SELECT   
                        '9999', m.ghi_prov_num ,
                            m.location provloc,
                           null  ,
                           null  ,
                            n.npi_num  ,
                            null ,
                            m.lastname ,
                            m.firstname  ,
                            null,
                            null  ,
                            null  ,
                            m.street1  ,
                            m.street2  ,
                            m.city ,
                            m.state  ,
                            m.zip5 ,
                            m.phone  ,
                            null  ,
                            null  ,
                            null  ,
                            null  ,
                            null
                           FROM dental_provider m, npi n,test_provider_pin pin
                       WHERE m.ghi_prov_num=n.tax_id(+)
                           and m.location=n.location(+)
                            and pin.tax_id=m.ghi_prov_num;The query takes for ever;
    But Individual query takes less than a sec to execute.Is there any way can i rewrite the query?
    Please help
    Hena.

    user11253970 wrote:
    But Individual query takes less than a sec to execute.Is there any way can i rewrite the query?Have a feeling you are using Toad/SQL Navigator or similar tool which returns data one screen at a time. If so, then it does not "takes less than a sec to execute" but rather to fetch first screen of rows. When you use UNION Oracle has to return distinct rows from both queries. Therefore it must fetch not just first screen but all rows. To verify, issue first query and in yiour GUI tool click on get last screen. Then you'll know how long whole select takes. Do the same for second query. Also, do you need distinct rows or akll rows? IF all rows, change UNION to UNION ALL.
    SY.

  • How to use union statement with declare & set function?

    Hi Experts,
            i  have small query about how to use union statement with declare & set function?
    Example as below :
    DECLARE @name AS date
    Declare @name2  AS date
    /* SELECT FROM [2013].[dbo].[OINV] T0 */
    /* WHERE */
    SET @name = /* T0.DocDate */ '[%1]'
    SET @name2 = /* T0.DocDate */ '[%2]'
    select  '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2013.dbo.orct t1
    inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2013.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]
    Union
    /* SELECT FROM [2014].[dbo].[OINV] T0 */
    /* WHERE */
    SET @name = /* T0.DocDate */ '[%1]'
    SET @name2 = /* T0.DocDate */ '[%2]'
    select  '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2014.dbo.orct t1
    inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2014.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between [%1] and [%2]

    You have to create stored procedure in SQL only .
    Like u must have create for Crystal .
    You can execute procedure in query manager but you have to enter parameter manually..
    example
    Exec @Test '20140101' '20140501'
    Every time user has to enter it manually in yyyymmdd format in case of date parameters.
    Example
    Create Proc [@Test]
    as begin
    DECLARE @name AS date
    Declare @name2  AS date
    /* SELECT FROM [2013].[dbo].[OINV] T0 */
    /* WHERE */
    select  '2013',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2013.dbo.orct t1
    inner join 2013.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2013.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2013.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2013].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between @Name and @Name2
    Union
    /* SELECT FROM [2014].[dbo].[OINV] T0 */
    /* WHERE */
    select  '2014',t5.U_salmannm,t1.CardName,t2.sumapplied as CollectionAmount,t2.DcntSum ,t3.DocTotal as InvoiceTotal,
    datediff(dd,t3.DocDate,t1.Docdate) as Days
    from 2014.dbo.orct t1
    inner join 2014.dbo.RCT2 t2 on t1.DocNum = t2.DocNum
    left join 2014.dbo.oinv t3 on
    t3.docentry = t2.baseAbs
    inner join 2014.dbo.ocrd t4 on t1.Cardcode = t4.CardCode
    inner join [2014].[dbo].[@CQ_RTSM] t5 on t4.U_BeatCode = t5.U_RoutCode
    where t2.DcntSum <> 0.000000 and t3.DocDate between
    between @Name and @Name2
    end

  • SQL query error using Union

    Hello!
    I need some correction in the following query. I am trying to make a 2 page QPLD so I am joining 2 queries and then printing the report into 2 pages.
    SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
    T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
    T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
    T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
    T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch]
    FROM OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Union all
    SELECT T0.[U_ModelType], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
    T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
    FROM OINS T0 WHERE
    T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Do I have to use the where clause just once since it is identical to both statements?
    I get the error stating that all queries using Union, Intersect or Except must have an equal number of expressions. what does this mean?
    scorp
    Edited by: scorpion 666 on Feb 12, 2009 1:30 PM

    Union has to have exact same numbers of fields to combine two results.  Your query shows no need of union because your where clauses are identical.
    Right syntax would be like this:
    SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
    T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
    T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
    T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
    T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
    T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
    FROM DBO.OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
    Thanks,
    Gordon

  • Using 2 Universe Queries in Crystal Reports

    Hi,
    I am trying to use Universe queries in a Crystal report.
    I want to use 2 Universe queries and then link the common dimensions between them using the Database Expert,   is these similar to merge dimensions in Web Intelligence?. Is it possible? Or how can I do to merge objects that came from 2 Universe queries?
    My problem is when I tried to execute the report, Crystal Reports get stuck.
    Any ideas would be helpful.
    Thanks in advance,
    Diana

    Moved to Universe Design forum

  • Performance using union

    I am using union of around 6 queries in a report. The same query in the database runs faster where as the report takes long time. Please suggest what can be done.
    thanks,
    deep

    Since union does an extra sort it has a performance difference compared to union all.
    SQL> select user from dual union select user from dual ;
    USER
    HR
    SQL> select user from dual union all select user from dual ;
    USER
    HR
    HRİf there is up to date and appropriate object statistics Oracle's Cost Based Optimizer will choose best access path, join method and join order depending on your query. Only exceptions are hints, outlines and sql profiles since they stabilize the execution plan.
    For further commenting please post your oracle version, query's test results and its statistics taken from sql*plus timing and autotrace options - http://www.bhatipoglu.com/entry/17/oracle-performance-analysis-tracing-and-performance-evaluation

  • Find intersection/union between two maps

    Hello.
    I'm trying to find out state changes between two maps.
    I have two maps A and B, what I need to do is to find keys in A that doesn't exists in B and keys in B that doesn't exist in A.
    If keys exists in both A and B I want to compare the values of those keys.
    What would be the most effective way to implement this.
    My first plan was to loop through the keys in A to find in B and loop through keys in B and find in A but I guess there is a more effective algorithm.
    I'm also thinking about using java.util.Collections to find intersection/union between the keys in the maps but then I need to do a lookup in both
    maps.
    Any suggestions?
    Regards
    /Fredrik

    Fredrik wrote:
    My scenario is this:
    I'm writing a Swing app for administration of a clustered environment.
    The keys in the map contains ip-address of cluster nodes, the value is a status/state for a node in the cluster.
    I want to signal state change for the node in the GUI.
    A state change happens if there is a new node in the cluster which means a new entry in the map since last checked or if a node
    leaves the cluster a remove of entry in the map since last checked or if the status/state for the entry/ip has changed since last checked.
    Regards
    /FredrikBy your above senario, i don't think you have two objects of Map, there is only one object and you want to signal the change in GUI, whenever a object is added , removed or only value is changed (Key is same) to the Map.
    Then i'll suggest below things:
    1) to override hashcode and equal method. (Because whenever the put or putAll methods are called the hashcode and equal method checks in the bucket for equal and similar hashcode, and if its equal , then change the GUI for the existing Map).
    2) As suggested earlier, override remove methods. (Whenever any object is removed, accordingly you can change the GUI).
    3) As suggested earlier, override put and putAll method( whenever a new object is added, accordingly you can change the GUI).
    And for this, i don't think you have iterate through the Map.

  • Error while adding a used relationship between the New DC and the Web DC

    Hi Gurus
    We are getting the Error in NWDS while Adding  a used relationship between the New DC and the Web DC.
    Steps what we are Done
    1. Create the custom project from inactiveDC's
    2.creating the project for the component crm/b2b in SHRAPP_1
    3.After that we changed the application.xml and given the contect path.
    4.Then we tried to add Dependency to the custom create DC we are getting the error saying that illegal deppendency : the compartment sap.com_CUSTCRMPRJ_1 of DC sap.com/home/b2b_xyz(sap.com.CUSTCRMPRJ_1) must explicitly use compartment sap.com_SAP-SHRWEB_1 of DC sap.com/crm/isa/ like that it was throwing the error.
    so, we skip this step and tried to create the build then it is saying that build is failed..
    Please help us in this regard.
    Awaiting for ur quick response...
    Regards
    Satish

    Hi
    Please Ignore my above message.
    Thanks for ur Response.
    After ur valuble inputs we have added the required dependencies and sucessfully created the projects, then building of the  projects was also sucessfully done and  EAR file was created.
    We need to deploy this EAR file in CRM Application Server by using the interface NWDI.
    For Deploying the EAR into NWDI, we need to check-in the activites what i have created for EAR. once i check-in the activites ,the NWDI will deploy the EAR into CRM Application Server.
    In the Activity Log we are able to check the Activities as Suceeded but the Deployment column is not showing any status.
    When i  right click on my activity Id the deployment summery is also disabled.
    So finally my Question is that where can i get the deployment log file, and where can i check the deployment status for my application..
    Any pointers in this regard would be of great help..
    Awaiting for ur valuble Responses..
    Regards
    Satish

  • How do I use iMessage between an iPhone & an iPod Touch?

    How do I use iMessage between an iPhone & an iPod Touch?

    Set up iMessage on both devices and when th touch has wifi you can iMessage to it

  • Adding new column in an existing report which was build using Union

    While working in OBIEE 11g I encounter an issue.
    My existing report was build using UNION at Criteria Tab in Analysis. Now I have a requirement to add a new column into the same report. For each criteria I have added the new column but when I go back to the "Result Columns". I see a new field added but it is not allowing me to open or edit column properties for that new column & at the same time it is not allowing me to navigate to other tabs like Results, Promts, and Advanced.
    I don’t want to build this report from scratch. Is there any workaround to get it resolved?

    Hi,
    Just check it once the new added column data types are mismatched or not?
    and the new added column should be navigated into excluded section, so u should edit the report and dragged into the table column section.
    Thanks..

  • After upgrading to YOSEMITE, I tried to use Airdrop between my iMac and iPhone 6 Plus but they don't recognize each other. It also didn't recognize my iPad. I need help

    After upgrading to YOSEMITE, I tried to use Airdrop between my iMac and iPhone 6 Plus but they don't recognize each other. It also didn't recognize my iPad.
    Please help!

    After upgrading to YOSEMITE, I tried to use Airdrop between my iMac and iPhone 6 Plus but they don't recognize each other. It also didn't recognize my iPad.
    Please help!

  • I just bought an iPad and want to set things so I can use Facetime between my iPad and my iMac.  How do I set up a new Apple ID for my iPad?

    How do I set up a new Apple ID iPad2 so I can use Facetime between my iPad2 when I'm on the road and my iMac at home? 

    All you need is the 99 cent Facetime for Mac application on your iMac.  Get it here:  http://www.apple.com/mac/facetime/
    Instructions for setting up your iPad are in Chapter 7 of the iPad2 iOS4.3 User Guide

  • How do i set up apple account on iphone to use icloud between my iphone and ipad

    how can i set up apple account on my iphone 4 so i can use icloud between my iphone and ipad

    To set up iCloud on the iPhone and iPad, ensure your software for these devices is up to date.  Once it is, see the following article - http://www.apple.com/icloud/setup/

  • Can i set up my iPad and iPod to use iMessage between the two devices with the same Apple ID?

    Can i set up my iPad and iPod to use iMessage between the two devices with the same Apple ID? SO i could iMessage if out from my iPod to my iPad at home to be viewed by a family member?

    Look into using Apple Configurator.  It's the easiest way to "reimage" and Manage iPads that I know of right now. 
    http://itunes.apple.com/us/app/apple-configurator/id434433123?mt=12
    Also, look into using the Educational Volume Purchase Program, if you have not already done so. 
    http://www.apple.com/education/volume-purchase-program/

Maybe you are looking for

  • Report on characteristic "date"

    Hi all, I need to report on characteristic "date" not only characteristic "period/year" in report painter in CO-PA costing based. How can I do that? Thanks for any help! HuyenTT

  • JNI UnsatisfiedLinkError in Weblogic 5.1.0 SP 8

    I am running Weblogic 5.1.0 with service pack 8 on solaris. We are using a web application called ecare. Servlets are under:myserver/ecare/web-inf/classes/servletsThe JavaBean that uses JNI to connect to the C code is under:myserver/ecare/web-inf/cla

  • Passing pl/sql array to function

    Hi, I have a function which takes an array: create or replace FUNCTION execute_tests( leg_keys IN type_leg_key_array) RETURN BOOLEAN IS BEGIN leg_key_array is this: create or replace TYPE type_leg_key_array AS TABLE OF NUMBER(6, 3); I would like to t

  • Osx mountain lion not downloading

    My download of osx mountain lion gets to 142mb then stops! I've tried deleting the purchase and redownloading still the same thing, does anyone have an answer for this annoying issue!

  • Doubt about Sync and Async process

    hi experts i have one small doubt if we r having the scenario like file to rfc iam passing the input parameter like material number through file  adapter and then i want to get the material details response from rfc sap r/3 to file system this is the