Issue while using SUBPARTITION clause in the MERGE statement in PLSQL Code

Hello All,
I am using the below code to update specific sub-partition data using oracle merge statements.
I am getting the sub-partition name and passing this as a string to the sub-partition clause.
The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
We are using Oracle 11gr2 database.
Below is the code which I am using to populate the data.
declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin
FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
FROM ( SELECT DISTINCT
TO_CHAR (batch_create_dt, 'YYYY') year_val
FROM stores_comm_mob_sub_temp
ORDER BY 1)
ORDER BY year_val)
LOOP
lv_partition_name :=
scmsa_handset_mobility_data_build.fn_get_partition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_search_string => m1.year_val);
FOR m2
IN (SELECT DISTINCT
'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
LOOP
lv_subpartition_name :=
scmsa_handset_mobility_data_build.fn_get_subpartition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_partition_name => lv_partition_name,
p_search_string => m2.month_val);
                    DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
IF lv_subpartition_name IS NULL
THEN
                         DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
SELECT t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt
FROM stores_comm_mob_sub_temp t2
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val;
ELSIF lv_subpartition_name IS NOT NULL
THEN
                    DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1 --> Issue Here
USING (SELECT *
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') =
m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val) T2
ON (T1.store_id = T2.store_id
AND T1.ntlogin = T2.ntlogin)
WHEN MATCHED
THEN
UPDATE SET
t1.postpaid_totalqty =
(NVL (t1.postpaid_totalqty, 0)
+ NVL (t2.postpaid_totalqty, 0)),
t1.sales_transaction_dt =
GREATEST (
NVL (t1.sales_transaction_dt,
t2.sales_transaction_dt),
NVL (t2.sales_transaction_dt,
t1.sales_transaction_dt)),
t1.batch_create_dt =
GREATEST (
NVL (t1.batch_create_dt, t2.batch_create_dt),
NVL (t2.batch_create_dt, t1.batch_create_dt))
WHEN NOT MATCHED
THEN
INSERT (t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
VALUES (t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt);
END IF;
END LOOP;
END LOOP;
COMMIT;
end;
Much appreciate your inputs here.
Thanks,
MK.
(SORRY TO POST THE SAME QUESTION TWICE).
Edited by: Maddy on May 23, 2013 10:20 PM

Duplicate question

Similar Messages

  • Question on passing string values to Partition clause in a merge statement

    Hello All,
    I am using the below code to update specific sub-partition data using oracle merge statements.
    I am getting the sub-partition name and passing this as a string to the sub-partition clause.
    The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
    We are using Oracle 11gr2 database.
    Below is the code which I am using to populate the data.
    declare
    ln_min_batchkey PLS_INTEGER;
    ln_max_batchkey PLS_INTEGER;
    lv_partition_name VARCHAR2 (32767);
    lv_subpartition_name VARCHAR2 (32767);
    begin
    FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
    FROM ( SELECT DISTINCT
    TO_CHAR (batch_create_dt, 'YYYY') year_val
    FROM stores_comm_mob_sub_temp
    ORDER BY 1)
    ORDER BY year_val)
    LOOP
    lv_partition_name :=
    scmsa_handset_mobility_data_build.fn_get_partition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_search_string => m1.year_val);
    FOR m2
    IN (SELECT DISTINCT
    'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
    LOOP
    lv_subpartition_name :=
    scmsa_handset_mobility_data_build.fn_get_subpartition_name (
    p_table_name => 'STORES_COMM_MOB_SUB_INFO',
    p_partition_name => lv_partition_name,
    p_search_string => m2.month_val);
                        DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
    IF lv_subpartition_name IS NULL
    THEN
                             DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
    INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
    t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    SELECT t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt
    FROM stores_comm_mob_sub_temp t2
    WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val;
    ELSIF lv_subpartition_name IS NOT NULL
    THEN
                        DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
    MERGE INTO (SELECT *
    FROM stores_comm_mob_sub_info
    SUBPARTITION (lv_subpartition_name)) T1
    USING (SELECT *
    FROM stores_comm_mob_sub_temp
    WHERE TO_CHAR (batch_create_dt, 'YYYY') =
    m1.orig_year_val
    AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
    m2.month_val) T2
    ON (T1.store_id = T2.store_id
    AND T1.ntlogin = T2.ntlogin)
    WHEN MATCHED
    THEN
    UPDATE SET
    t1.postpaid_totalqty =
    (NVL (t1.postpaid_totalqty, 0)
    + NVL (t2.postpaid_totalqty, 0)),
    t1.sales_transaction_dt =
    GREATEST (
    NVL (t1.sales_transaction_dt,
    t2.sales_transaction_dt),
    NVL (t2.sales_transaction_dt,
    t1.sales_transaction_dt)),
    t1.batch_create_dt =
    GREATEST (
    NVL (t1.batch_create_dt, t2.batch_create_dt),
    NVL (t2.batch_create_dt, t1.batch_create_dt))
    WHEN NOT MATCHED
    THEN
    INSERT (t1.ntlogin,
    t1.first_name,
    t1.last_name,
    t1.job_title,
    t1.store_id,
    t1.batch_create_dt)
    VALUES (t2.ntlogin,
    t2.first_name,
    t2.last_name,
    t2.job_title,
    t2.store_id,
    t2.batch_create_dt);
    END IF;
    END LOOP;
    END LOOP;
    COMMIT;
    end;
    Much appreciate your inputs here.
    Thanks,
    MK.

    I've not used partitioning, but I do not see MERGE supporting a variable as a partition name in
    MERGE INTO (SELECT *
    FROM stores_comm_mob_sub_info
    SUBPARTITION (lv_subpartition_name)) T1
    USING ... I suspect it is looking for a partition called lv_subpartition_name.
    I also don't see why you need that partition name - the ON clause should be able to identify the partition's criteria.

  • Error executing a stored procedure from SSIS using the MERGE statement between databases

    Good morning,
    I'm trying to execute from SSIS a stored procedure that compares the content of two tables on different databases in the same server and updates one of them. To perform this action, I've created a stored procedure in the destination database and I'm
    comparing the data between tables with the MERGE statement. When I execute the procedure on the destination database the error that I obtain is:
    "Msg 916, Level 14, State 1, Procedure RefreshDestinationTable, Line 13
    The server principal "XXXX" is not able to access the database "XXXX" under the current security context."
    Some things to take in account:
    1. I've created a temporary table on the same destination database to check if the problem was on the MERGE statement and it works fine.
    2. I've created the procedure with the option "WITH EXECUTE AS DBO".
    I've read that it can be a problem of permissions but I don't know if I'm executing the procedure from SSIS to which user/login I should give permissions and which.
    Could you give me some tip to continue investigating how to solve the problem?
    Thank you,
    Virgilio

    Read Erland's article http://www.sommarskog.se/grantperm.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Managing the first application of the MERGE statement in an ETL logic - SQL Server 2012

    Hi,
    in order to feed a fact table of a dwh from a staging table I'm using the MERGE statement in order to control insert and update operations. It is possible that the staging table has duplicate rows respect to the fields controlled in the merge condition:
    when I run the first time the MERGE statement unwanted rows could be inserted in the fact table.
    Does the MERGE statement allow to manage this case or do I need to filter data from the staging table before to write them into the fact table?
    Many thanks

    Hi Anuj,
    thank for your reply. Unfortunately the DISTINCT in the using clause isn't enough for my case: I need to read a subset of fields of a staging table and for this subset I could have duplicate rows, but also I need to the change date of the rows inserted in
    the staging table and I cannot include this date in the distincted columns.
    However the answer is that I need to handle the staging data before to write them into the fact table.
    Thanks
    Yes
    One more thing to note is when running MERGE statement subsequently in case there are multiple records which matches the update criteria then default behavior of MERGE is to throw an error indicating that it tried to update same record twice.
    So in any case you need to make sure you eliminate duplicates before applying MERGE over it at first.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Help needed in the Merge Statement

    Hi All,
    I am using MERGE statement in my program. I want to maintain the log for the duplicate reords mean maintain the log for those reocrds which are updated in the merge statement.
    Can any one help me in this that how can i maintain the log?
    Thanks for your help in advance.
    kind Regards,

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:35615502072484

  • For the merge statement

    Hi,
    Is it possible to insert and update at the same time in the when not matched part of the MERGE statement.
    Pl provide me the information how to do it in MERGE statment.
    thanks in advance.

    Hi,
    Post an example of what you want to do.
    Include:
    (1) the version of Oracle you are using
    (2) the contents of the tables (both the destination table you are modifying and the soure table or tables) before the MERGE
    (3) the required contents of the destination table after the MERGE
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type {code} before and after the tabular text, to preserve spacing.

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • Issue while using SUNOPSIS MEMORY ENGINE (High Priority)

    Hi Gurus,
    While using SUNOPSIS MEMORY ENGINE to generate a .csv file using the database table as a source it is throwing an error in the operator like.
    ODI-1228: Task SrcSet0 (Loading) fails on the target SUNOPSIS ENGINE connection SUNOPSIS MEMORY ENGINE.
    Caused By: java.sql.SQLException: unknown token
    (LKM used : LKM Sql to Sql.
    IKM used : IKM Sql to File Append.)
    can you please help me regarding this ASAP as it has became the show stopper for me to proceed further.
    Any Help will be greatly Appreciable.
    Many Thanks,
    Pavan
    Edited by: Pavan. on Jul 11, 2012 10:22 AM

    Hi All,
    The Issue got resolved successfully.
    The solution is
    we need to change the E$_,I$_,J$_,...... to E_,I_,J_,.... ((i.e; removing the '$' Symbol)) in the PHYSICAL SCHEMA of SUNOPSIS MEMORY ENGINE as per the information given below.
    When running interfaces and using a XML or Complex File schema as the staging area, the "Unknown Token" error appears. This error is caused by the updated HSQL version (2.0). This new version of HSQL requires that table names containing a dollar sign ($) are surrounded by quotes. Temporary tables (Loading, Integration, and so forth) that are created by the Knowledge Modules do not meet this requirement on Complex Files and HSQL technologies.
    As a workaround, edit the Physical Schema definitions to remove the dollar sign ($) from all the Work Tables Prefixes. Existing scenarios must be regenerated with these new settings.
    It worked fine for me.
    Thanks ,
    Pavan Kumar

  • Performance hit using "where" clause in the query

    Hi All,
    I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
    1. SELECT * FROM Employee
    2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
    There is no difference in Query Execution Time for both queries.
    Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
    Rows returned are more in first case as compared to second case.(ratio - 1:4)
    Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
    Does anybody know the reason of unexpected time difference for the business logic in the second case?

    Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
    Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
    First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
    Second, you may need your DBA to enable autotracing, if it's not already:
    http://asktom.oracle.com/~tkyte/article1/autotrace.html
    http://www.samoratech.com/tips/swenableautotrace.htm
    Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
    For example:
    SQL> set autotrace on
    SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
      COUNT(*)
            11
    Execution Plan
    Plan hash value: 2983758974
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            |     1 |     4 |     1   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE   |            |     1 |     4 |            |          |
    |*  2 |   INDEX RANGE SCAN| TICKET_N10 |    12 |    48 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
    Statistics
              0  recursive calls
              0  db block gets
              1  consistent gets
              0  physical reads
              0  redo size
            515  bytes sent via SQL*Net to client
            469  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
    the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
    If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
    since sql*plus is not a JDBC thing...
    Oh, and sql*plus can also give you easier access to timing information, with "set timing on".

  • Mapping issues while using MapwithDefault Node function for Idoc

    Hi Experts,
    We are facing issues while trying to generate nodes at reciver side even though it does not exist at sender side.
    we are using the matmas05 and we want the nodes E1marcm and e1mardm to generated at target structure.
    the structure is like this
    Matmas05
    idoc
    E1maram
    segment
          E1marcm
            segment
              msgfn
              .....other fields
              E1mardm (can be many segments)
                segment 
                  lgort
                  ..other fields
              E1mpgdm
                 segment
                 ...e1mpgdm fields
    the mapping has been done like:
    e1marcm -mapwithdefault-e1marcm
    constant -segment
    werks-mapwithdefault-werks
    other fields(one to one mapping)
    e1mardm-mapwith default-e1mardm
    lgort-mapwithdefault(value 1000)-lgort
    other fields -one to one mapping
    now the problem we are facing is when e1mardm is not existing in source structure the values from the other node of e1mardm(which exists) are getting overwritten into it.
    we want only the lgort to be 1000 and the segment should populate at target side.
    like
    e1mardm
    segment
    lgort value 1000
    Could you please assist in solving this issue and give your valuable suggestions as how could we handle it.
    Thanks and regards,
    jyoti

    U will achieve this using UDF function. Map the below Like.
    e1mardm-mapwith default(Value Constant)-e1mardm
                                                            lgort (A) ---
    e1mardm-mapwith default(Value Exit)u2014(EqualsS) (B)- (UDF1)- lgort
                                Constant(Value Exit)---   
                                              Constant(Value 1000)(C)---   
    Other one to one mapping fields also you should use one more UDF.
                        Other one to one fields (A) ---
    e1mardm-mapwith default(Value Exit)u2014(EqualsS)    (B) - (UDF2)- Target
                                 Constant(Value Exit)---   
    UDF1:
    Argument A,B,C and select queue.
       //write your code here
    int j = 0;
    for(int i=0;i<a.length;i++)
    if (b[j].equals("true"))
    result.addValue(c[0]);
    i--;
    result.addValue(ResultList.CC);
    else
    result.addValue(a<i>);
    j++;
    UDF2:
       Argument A,B and select queue.
        //write your code here
    int j = 0;
    for(int i=0;i<a.length;i++)
    if (b[j].equals("true"))
    i--;
    result.addValue(ResultList.CC);
    else
    result.addValue(a<i>);
    j++;

  • Apple Cinema Display 23" brightness issue while using with Microsoft Vista

    Hello there,
    I have the following issue and was wondering if someone has an idea what the reason is or what can I do to fix this:
    I have a 23" Apple Cinema Display running with a MacPro 2,8 GHz. When I switch to PC using BootCamp 2.1 with Windows Vista Service Pack 1 32bit the screen becomes extremely dark.
    At first, on the PC side, the display has the correct brightness but after two seconds it switches to a very low brightness setting.
    When I go back to the Mac side the brightness setting on my Cinema Display has changed to the lowest point.
    I also have a MacBookPro, with Microsoft XP installed also using BootCamp (I cannot find the version of this Boot Camp, but it is an earlier version) to change to PC. In XP, there is a driver installed that allows me to use a slider on the PC to control the monitor brightness. But with Vista this slider is nonexistent.
    I already tried changing the graphic's card NVIDIA 8800 driver to see if I can manipulate the brightness on the monitor. I realized there is brigthness slider on the Nvidia driver, but when you make brighter, the colors just get messed up, and the brightness stays as dark as before.
    We have lately upgraded to Snow Leopard and had installed Spyder on the Mac side to create a monitor profile for the Cinema Display. I already deleted the profile to see if there is a change. Nothing. I already went back in time on my PC (Restore Point), also nothing.
    Could I download a driver for Vista, so that I have a brightness slider on the PC side, so that I can adequately change the brightness to its correct setting.
    It is amazing how the lack of correct brightness in a monitor, can ruin your entire working day! Very frustrating!
    It would be greatly appreciated if someone has a solution for this issue! Thanks a lot!
    Emil

    Okay, I came across a thread that implies there is a problem with using the Apple ADC-to-DVI adapter to attach the older "acrylic" 23" Cinema Display to a Mac Pro DVI graphics card. Basically, the workaround is to NOT use the USB part of the adapter (disconnect it).
    1) In OS X, set the desired display brightness.
    2) Disconnect the USB cable coming from the converter to the Mac.
    3) Restart into Windows.
    The brightness setting should now remain as it was under OS X.
    Confirmed to work on my Mac Pro v1,1 (dual 2.66 Core 2 Duo) with nVidia GeForce 7300 GT video card running Windows 7 x64.
    Link here: <http://forums.macrumors.com/showthread.php?t=790910> for credit to resolution.
    Of course, you lose the functionality of the 2-port built-in USB hub in the Cinema Display, but an external USB hub can make up for that.

  • Authorization issue while using business content objects

    Hi all,
    I am getting an authorization error while loading from DSO to Cube (for standard business content objects only). Even i am not able access the data in Bex reports from Standard cubes or DSO.
    The user is assigned to SAP_ALL .
    But there is no such issue while accessing user defined DSO or cubes.
    any solutions will be helpful.
    Regards,
    Varma

    Hi,
    Have you seen the error thru the SU53 t-code ? There you should see what is the missing authorization with the user.
    Regards, Federico

  • I am frequently experiencing Iphone 5 camera issues, while taking photos all of the sudden the camera going to hang mode

    Hi,
    Greetings !!!
    I would like to know what is the root cause of Iphone camera hanging ?
    I am very frequently experiencing Iphone 5 camera issues like while taking photos all of the sudden the camera going to hang mode with full of pink & black line.
    I noticed while camera app turns ON the phone going to hand.
    I went to apple services server with this problem & they said they didn't see any errors.
    Kindly response with my request, and provide me the solution.
    Thannks & regards,
    -Vamsi

    That often happens with cameras when you take pictures of a computer screen. LCD screens "flicker" and the camera will often catch the flicker.

  • Issues while joining two tables as the joining column has duplicate values - Please help!

    Hi,
    I have a table A -which has few columns including a Amount column - I am joining this table A to Table B. The joining column in B has duplicates.  So, the number of records are getting more after the joining. As per the requirment when I create a table
    after joining the tables and count the salary clumn, there is a difference in the counting. How can I solve this? Can you please help me?
    Here is the DDL and sample values
    create table #student (sid int, name varchar(10),salary int)
    create table [#address] (sid int, city varchar(10),grade char(1),lineneumber int)
    insert into #student values (1,'sachin',8000)
    insert into #student values (2,'Dhoni',2000)
    insert into #student values (3,'Ganguly',7000)
    insert into #student values (4,'Kohli',1000)
    insert into [#address] values(1,'mumbai','A',1)
    insert into [#address] values(1,'mumbai','B',2)
    insert into [#address] values(1,'mumbai','C',3)
    insert into [#address] values(1,'mumbai','D',4)
    insert into [#address] values(2,'JARKHAND','D',3)
    insert into [#address] values(2,'JARKHAND','D',4)
    SELECT S.SID,NAME,salary,CITY ,grade,linenumber
    into #FINAL
    FROM #STUDENT S
    LEFT JOIN #ADDRESS A
    ON S.SID=A.SID
    SELECT SUM(salary) FROM #FINAL
    --44000
    Final result should be 18000 , but it is coming as 44000. can you please help me to get the correct result - what do i do in the joining?
    In my real project, i have 5 tables joining, each table have more than 30 columns and few joining tables joining column have duplicates. I have simplified the issue so that i can ask the question clearly. So,while answering, please consider that also in mind.
    thanks in advance for your help!

    SELECT S.SID,NAME,salary,CITY 
    into #FINAL
    FROM #STUDENT S
    LEFT JOIN (SELECT DISTINCT sid,city
    FROM #Address) A
    ON S.SID=A.SIDthis will do a join on student table and city table with unique sid and city name so adddress selection will be sid city1 mumbai2 jarkand

  • I had a major power out last night while using Lr5 Help with the below please

    I had a major power out last night while using Lr5, we have power back now but when launching Lr5 i get this error and I have rebooted 2 times nows with no results. I have a normal pc, and this is the error message i am getting.......Lightroom encountered an error when reading from its preview cache and quit, so i say ok and still nothing works. i am trying to process my event photos from yesterday and i need to get this fixed urgently!!! please help

    Delete the Preview Cache folder.
    It is in the same main folder as the LR catalog. Usually in your Username folder.
    Once delete LR will rebuild it once LR is opened.

Maybe you are looking for

  • Why do I get a black version when I convert my document to PDF?

    I have been using Microsoft Publisher 2007 with XP to produce a newsletter for over 11/2 years. Today when I converted the file to PDF it is black with all kinds of wierd colors. It looks nothing like the document I produced. This has never happened

  • Jk to ajp / windows to solaris 10 / big delay on socket read

    I'm having a delay problem only on Solaris 10 using the Tomcat connector from IIS to Solaris. I've posted this issue on a couple of Java and Solaris forums with no luck. Hopefully, this forum will have the correct audience. I have: - IIS 6, Windows 2

  • LICENSING FOR THIS PRODUCT HAS STOPPED WORKING. Error: 150:30.

    Yesterday I purchased a new MBPro 15" Retina display. I retrieved all my files from TimeCapsule and I have a separate login when working with these files. On this login, photoshop, illustrator and indesign from CS4 appear on the dock. But when I go t

  • Installing new RAM and need help!

    Hello everyone, I have this exact same computer model found here: http://wow-rebates.com/lenovo-3000-k100-57068352-intel-desktop-pc/ This means that I have 4 slots of RAM, but 3 are currently being used by 1 GB sticks of DDR2 PC2-5300 @ 667. I just b

  • Cannot view pdf in snow leopard in safari, cannot view pdf in snow leopard in safari

    I have a MacBookPro  Duo Core   that I just installed Snow Leopard on, Now I cannot view pdf's online in either Safari or FireFox. And I am getting  a message when I open Safari that it does not support community toolbar.