Point in Poly query?

How do I perform a simple point in poly query with spatial?
If I have a set of coordinates (-86.524442 39.7748187) for which I want to know which polygon they fall inside of?
Thanks in advance-M.

A query like this should get what you're after :
select county
from counties c
where sdo_relate(c.geom, mdsys.sdo_geometry(2001,
null,
mdsys.sdo_point_type(-86.524442,39.7748187,null),
null, null),
'mask=contains querytype=window') = 'TRUE'
This will return "Hendricks" county which I believe is correct.
The relevant parms for the mdsys.sdo_geometry object are the "2001" which specifies a point object and then the creation of the actual sdo_point_type itself. The third parm to this object is null as that is the Z access.
The Oracle Spatial Users Guide is very useful and has lots of information and examples of this kind of thing.
Steve

Similar Messages

  • Spatial query (point in poly) problem

    Hi
    One of my users is trying to run the following query in SQL*Plus:
    CREATE TABLE erdpwip_join AS
    SELECT A.CSNGC, B.PARCELID
    FROM RLR.RLR87_SK B, ERDPWIPDATA A
    WHERE sdo_relate (a.geom, b.geom, 'mask=ANYINTERACT querytype=Window') = 'TRUE'
    He says it works on a small subset of the full dataset, but when he tries to run it on a larger selection of data it stops working. The full dataset has 1.6 million shapes and is held in an Oracle 9.2.0.5.0 database. It isn't clean data, unfortunately: I performed an sdo_geom.validate_layer_with_context on it and removed around 240 shapes with errors (mostly self-intersects), but when trying to access the dataset through ESRI's ArcSDE (version 8.3) a load_buffer error -2035 occurs, which I am informed is because there are other low-level self-intersects which Oracle's validation routine didn't pick up.
    There are two questions really: first, is the quality of the data (with these geometric errors) the reason for the user's point-in-polygon query not working on larger recordsets (e.g. about 400000 records), or is because of the volume of data?
    Secondly, is there any way that Oracle's validation routines will pick up these low-level self-intersects which were missed in the first pass? ESRI's support forum recommends running a query on the dataset which steps through so many records at a time until it finds an error - the full thread is at http://forums.esri.com/Thread.asp?c=2&f=1720&t=152985&mc=1.
    Any help would be appreciated.
    Thanks
    Sharon Evans

    Hi Sharon,
    What does "it stops working" mean? Error? Long running query?
    Assuming your data is now clean in spatial, I would try creating the table, then loading it with the query using the ordered hint. The number of geometries, while affecting run time, is certainly not more than spatial can handle.
    CREATE TABLE erdpwip_join AS
    SELECT A.CSNGC, B.PARCELID
    FROM RLR.RLR87_SK B, ERDPWIPDATA A
    WHERE rownum < 1;
    insert into erdpwip_join
    SELECT /*+ ordered */ A.CSNGC, B.PARCELID
    FROM RLR.RLR87_SK B, ERDPWIPDATA A
    WHERE sdo_relate (a.geom, b.geom, 'mask=ANYINTERACT querytype=Window') = 'TRUE';
    Regarding drawing in ESRI and tolerance/validation:
    In Oracle Spatial the tolerance is specified as the distance two points have to be apart to be considered different.
    I think for ESRI, points have to be greater than tolerance apart (not exactly tolerance apart, which is fine in spatial).
    So what you might want to try is kicking up the tolerance by some very small increment for the validation, remove or fix those invalid geometries, reset the tolerance back to the smaller value, and then try using ArcSDE again.
    I haven't tried this at all, so if you can let us know if this works we'll know this is probably a good general recommendation.

  • Point-in-polygon query with SDO_GEOMETRY.RELATE

    Hello All,
    I'm trying to perform a simple point-in-polygon query using
    SDO_GEOMETRY.RELATE. Only the "anyinteract" mask seems to return
    the correct answer. Can someone point out what I'm doing wrong
    and/or suggest a better way to do this. My objective is simply
    to return a count of the number of features in the point table
    that fall with the selected feature in the polygon table.
    select count(*) count from pnttest pnt, polytest poly,
    user_sdo_geom_metadata m where SDO_GEOM.RELATE(pnt.shape,
    m.diminfo, 'anyinteract',poly.shape,m.diminfo) = 'TRUE'
    and m.table_name = 'POLYTEST' and m.column_name = 'SHAPE' and
    poly.ADMIN_NAME = 'California'
    I would have thought the "inside" mask would be what I want but
    it returns 0 instead of the correct answer of 6.
    Thanks for any help or suggestions!
    -- john

    Hi John,
    If I wanted to do this as fast as possible, and didn't mind
    returning points that touch the boundary of the polygon, I would
    do something like this (assuming the point layer is indexed):
    select /*+ ordered */count(*) count
    from polytest poly, pnttest pnt
    where SDO_RELATE(pnt.shape,poly.shape,
    'mask=anyinteract querytype=window') = 'TRUE'
    and poly.ADMIN_NAME = 'California';
    If you are wondering what relationship Oracle Spatial thinks
    there is between the 6 points and the state, try using the
    determine mask with the 6 geometries that return from
    anyinteract.
    If you are using Oracle Spatial pre-9i, you might also want to
    add layer_gtype=point in the quotes.
    Hope this is useful.
    dan

  • Change a favorite/Bookmark so it point to another query.

    We are using BW web as front end
    What we want is:
    Change a favorite so it point to another query.
    The scenarie is that we have a query that does not work anymore and instead of changing it we create a new query. This means that all the bookmarks/favorites that users has created will not work.
    Is there a solution on how to find and relocate these bookmarks/favorites? It will save the users and the support line for a lot of work.

    herms-ra,
    now i cant de-expand?
    Undo (Ctrl/Cmd+Z) may be your only friend (until it is too late).
    how do i isolate a path/segment with the direct select tool?
    It is important to have the path/object deselected before using the Direct Selection Tool; you may do that by clicking an empty spot on the artboard, then clicking the segment of your choice.

  • Point in poly tuning suggestions?

    I have a static table with 250 non-overlapping polygons. I wrote a function to accept a point and perform a point in poly calculation (sdo_relate) and do nearest neighbor if no poly contains the point. An application calls this function about 1.5 million times a day. The function performs pretty well (executes about 15 times per sec.) most of the time, but falls behind during peak application times. For both resource reasons and application reasons, I can not thread this out.
    Usually the application has other metadata that can narrow the list of potential polygons down to 2 or 3. I tried including this into the function by adding "where column_3 in (1,54,...)" but saw no change in performance or execution plan for that matter. The sql in the function is inside and execute_immediate statement with bind params if that matters.
    The table and indexes have had stats run, and the sdo_tune.analyze_rtree reports that everything is good.
    This is on a 9.2.0.4 database on a compaq dl-360 (2-cpu) running RH Linux.
    Any tuning suggestions? It seems like I should be able to make it run faster driving off of the other column and only running sdo_relate against a couple of polys.

    Hi,
    sdo_relate always uses the spatial index, which in monolithic for the table - adding other attibutes won't limit the use of the index and relate.
    If you can narrow things down to one or two geometries, you might consider use of sdo_geom.relate with the one or two geometries you've narrowed things down to. It might be worth looking at.
    hope this helps - let us know.

  • Suggested query (9i) for 3-d Geodetic point-in-poly?

    Hi there,
    Just getting started with Spatial. Have a SDO_POINT_TYPE layer in 8307 (Geodetic Lat/Lon/Height) 3-dim, indexed with 2-dim (Lat/Lon) and want to know what the best way is to perform point-in-polygon queries on this layer (e.g. basic web-mapping interface)? I recently tried SDO_GEOM.RELATE but it was extremely slow, and incorrect....certainly something I'm doing wrong.
    Any help whatsoever is greatly appreciated.
    Thanks in advance,
    Michael

    Thanks very much.
    However, I the query doesn't seem to be giving me what I think it should. My index is two dimensions:
    create index I_MONUMENT_SHAPE on MONUMENT_CATALOG (SHAPE)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS('layer_gtype=POINT sdo_indx_dims=2');
    "SDO_RELATE" query:
    select mc.char_id as "ID",mc.shape as "Shape" from monument_catalog mc
    where SDO_RELATE(mc.shape,MDSYS.SDO_GEOMETRY(2003,8307,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),
    -- MDSYS.SDO_ORDINATE_ARRAY(-110,20,-110,30,-100,30,-100,20,-110,20)),'mask=inside querytype=WINDOW') = 'TRUE';
    MDSYS.SDO_ORDINATE_ARRAY(-110,20,-110,30,-100,30,-100,20,-110,20)),'mask=anyinteract') = 'TRUE';
    ID Shape(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    BURR SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-110.066, 23.516, 535.02537), NULL, NULL)
    ANCN SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-110.03, 23.739, 481.56558), NULL, NULL)
    LPAZ SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-110.319, 24.139, -26.9092), NULL, NULL)
    BLND SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-110.309, 24.326, -10.21309), NULL, NULL)
    "vanilla sql" query:
    select mc.char_id as "ID",mc.shape as "Shape" from monument_catalog mc
    where mc.shape.SDO_POINT.X < -100
    and mc.shape.SDO_POINT.X > -110
    and mc.shape.SDO_POINT.Y < 30
    and mc.shape.SDO_POINT.Y > 20;
    ID Shape(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    CEBO SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.161, 20.09, 2009.12022), NULL, NULL)
    JARA SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-101.8, 21.264, 2016.36392), NULL, NULL)
    UMON SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.453, 20.737, 1626.65695), NULL, NULL)
    ineg SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-102.284, 21.856, 1888.67922), NULL, NULL)
    AYUT SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-104.374, 20.188, 1648.7741), NULL, NULL)
    CHAC SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-105.429, 20.383, 280.64762), NULL, NULL)
    COSA SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.325, 20.293, 1730.68995), NULL, NULL)
    GUAC SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-104.354, 20.501, 1581.31376), NULL, NULL)
    MCAB SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.493, 21.092, 1682.41884), NULL, NULL)
    SEBA SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-104.871, 20.699, 1973.90223), NULL, NULL)
    ECER SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-109.81, 24.18, 89.31145), NULL, NULL)
    EMIR SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-109.735, 23.366, 192.75321), NULL, NULL)
    RIVE SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-109.532, 23.549, 40.95293), NULL, NULL)
    LIM2 SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.528, 20.335, 1652.13807), NULL, NULL)
    SAUZ SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.225, 20.885, 1699.7295), NULL, NULL)
    7122 SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-106.459, 23.343, 27.9281), NULL, NULL)
    3033 SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-109.086, 25.692, -30.58101), NULL, NULL)
    7882 SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-109.864, 22.918, 115.09006), NULL, NULL)
    LIMA SDO_GEOMETRY(3001, 8307, SDO_POINT_TYPE(-103.548, 20.37, 2112.2829), NULL, NULL)
    Any idea why the SDO_RELATE query seems to be giving me stuff just ---outside--- my query window rather that stuff that lies inside?
    Thanks,
    Michael

  • How to point an existing query into a new cube?

    Hello Experts,
    For a Business requirement, I had to create a new cube.
    Now, I wanted point out all my existing queries to the new Cube.
    Can someone please tell me how to do it?
    Point will be assigned for useful information.
    Thanks
    kumar

    Hello
    I Don't want all the queries to be copied to the new cube.Can we specify the query names in the transaction?
    It may be a dumb question but, can we the same for workbooks as well?
    Thanks
    Kumar

  • Check point query information

    Hello Team,
    one of my production server i am continually getting this error:
    [CHECK POINT FREE SPACE QUERY TIME OUT]
    this information we are getting through third party tools and IT team raise ticket to DBA team,
    Note:we checked sql server error log  due to this issue but there is no information for
    this issue each and every think works fine.
    how we can resolve this issue ,this alert getting daily
    4 or 5 times.

    Hello Team,
    one of my production server i am continually getting this error:
    [CHECK POINT FREE SPACE QUERY TIME OUT]
    this information we are getting through third party tools and IT team raise ticket to DBA team,
    Note:we checked sql server error log  due to this issue but there is no information for
    this issue each and every think works fine.
    how we can resolve this issue ,this alert getting daily
    4 or 5 times.
    From where did you get this error, as you said you have went through the SQL errorlog & no issues reported, then it is not related to the SQL database server, Also as you said it is 3rd party tool, then suggesting to check what that 3rd party tool it is
    for & where it configured & for what(like monitoring,application level query etc) & what inside described it.
    Thanks, Rama Udaya.K (http://rama38udaya.wordpress.com) ---------------------------------------- Please remember to mark the replies as answers if they help and UN-mark them if they provide no help,Vote if they gives you information.

  • This part of query is taking long time to run, its about 40 minutes. Can anyone help wit it.

    ------Load Dataset into Temp table---------------
    SELECT
    z.SYSTEMNAME
    --,Case when ZXC.[Subsystem Name] <> 'NULL' Then zxc.[SubSystem Name]
    --else NULL
    --End AS SubSystemName
    , CASE
    WHEN z.PROV_TAX_ID IN
    (SELECT DISTINCT zxc.TIN
    FROM dbo.SQS_Provider_Tracking zxc
    WHERE zxc.[SubSystem Name] <> 'NULL'
    THEN
    (SELECT DISTINCT [Subsystem Name]
    FROM dbo.SQS_Provider_Tracking zxc
    WHERE z.PROV_TAX_ID = zxc.TIN)
    End As SubSYSTEMNAME
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,SUM(z.SEQUEST_AMT) Actual_Sequestered_Amt
    , CASE
    WHEN z.SRC_PAR_CD IN ('E','O','S','W')
    THEN 'Nonpar Waiver'
    --**Amendment Mailed**
    --WHEN z.PROV_TAX_ID IN
    When EXISTS
    (SELECT DISTINCT b.PROV_TIN
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    where not exists (select * from dbo.sqs_objector_TINs t where b.PROV_TIN = t.prov_tin))
    THEN
    (SELECT DISTINCT b.Mailing
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    WHERE z.PROV_TAX_ID = b.PROV_TIN
    -- --**Amendment Mailed Wave 3 and 4**
    --WHEN z.PROV_TAX_ID In
    When EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Amendment Mailed (3rd Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin))
    THEN 'Amendment Mailed (3rd Wave)'
    WHEN EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Amendment Mailed (4th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin))
    THEN 'Amendment Mailed (4th Wave)'
    -- --Is Puerto Rico of Lifesynch
    WHEN EXISTS
    (SELECT DISTINCT a.PROV_TAX_ID
    FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK )
    WHERE a.Bucket <> 'Nonpar'
    THEN
    (SELECT DISTINCT a.Bucket
    FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK )
    WHERE a.PROV_TAX_ID = z.PROV_TAX_ID)
    -- --**Top Objecting Systems**
    WHEN z.SYSTEMNAME IN
    ('ADVENTIST HEALTH SYSTEM','ASCENSION HEALTH ALLIANCE','AULTMAN HEALTH FOUNDATION','BANNER HEALTH SYSTEM','BERT FISH MEDICAL CENTER','BETHESDA MEMORIAL HOSPITAL','BJC HEALTHCARE','BLOUNT MEMORIAL HOSPITAL','BOCA RATON REGIONAL HOSPITAL','CAROMONT HEALTH SYSTEM','CATHOLIC HEALTH INITIATIVES','CATHOLIC HEALTHCARE PARTNERS','CHRISTUS HEALTH',/*'CLEVELAND CLINIC HEALTH SYSTEM',*/'COLUMBUS REGIONAL HEALTHCARE SYSTEM','COMMUNITY HEALTH SYSTEMS, INC','COXHEALTH','HCA','HEALTH MANAGEMENT ASSOCIATES','HUNTSVILLE HOSPITAL HEALTH SYSTEM','INTEGRIS HEALTH','JUPITER MEDICAL CENTER','LEE MEMORIAL HEALTH SYSTEM','MARTIN MEMORIAL HEALTH SYSTEM','MERCY','MT SINAI MEDICAL CENTER (MIAMI)','MUNROE REGIONAL MEDICAL CENTER','NORMAN REGIONAL HEALTH SYSTEM','NORTHSIDE HEALTH SYSTEM','SHANDS HEALTHCARE','SISTERS OF MERCY - SPRINGFIELD, MO','SSM HEALTH CARE','ST LUKES HEALTH SYSTEM','SUMMA HEALTH SYSTEM','SUSQUEHANNA HEALTH SYSTEM','TBD -- TRINITY HEALTH - CATHOLIC HEALTH EAST','UNIVERSITY OF MISSOURI HEALTH SYSTEM','UNIVERSITY OF NEW MEXICO HOSPITALS','UNIVERSITY OF UTAH HEALTH CARE')
    THEN 'Top Objecting Systems'
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Top Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Top Objecting Systems'
    -- --**Other Objecting Hospitals**
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Other Objecting Hospitals'
    -- --**Objecting Physicians**
    WHEN EXISTS
    (SELECT z.PROV_TAX_ID
    FROM SQS_EDW_Source z WITH (NOLOCK)
    WHERE EXISTS
    (SELECT DISTINCT
    obj.TIN
    FROM SQS_Provider_Tracking obj WITH (NOLOCK )
    WHERE obj.[Objector?] in ('Objector','Top Objector')
    and z.PROV_TAX_ID = obj.TIN
    and z.LCLM_RSTMT_TREND_CAT_CD not IN ('HO','HI')
    THEN 'Objecting Physicians'
    --****Rejecting Hospitals****
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Rejecting Hospitals'
    --****Rejecting Physciains****
    WHEN EXISTS
    (SELECT obj.TIN
    FROM SQS_Provider_Tracking obj WITH (NOLOCK )
    WHERE z.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector')
    and z.LCLM_RSTMT_TREND_CAT_CD NOT IN ('HO','HI')
    THEN 'REjecting Physicians'
    ----**********ALL OBJECTORS SHOULD HAVE BEEN BUCKETED AT THIS POINT IN THE QUERY**********
    -- --**Non-Objecting Hospitals**
    WHEN EXISTS
    (SELECT DISTINCT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h WITH (NOLOCK )
    WHERE
    (z.PROV_TAX_ID = h.PROV_TAX_ID)
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Non-Objecting Hospitals'
    -- **Outstanding Contracts for Review**
    WHEN EXISTS
    (SELECT qz.PROV_TIN
    FROM
    [PACT].[HUMAD\ARS3766].[SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Non-Objecting Bilateral Physicians'
    AND z.PROV_TAX_ID = qz.PROV_TIN)
    Then 'Non-Objecting Bilateral Physicians'
    When EXISTS
    (select
    p.prov_tax_id
    from dbo.SQS_CoC_Potential_Mail_List p WITH (NOLOCK )
    where p.amendmentrights <> 'Unilateral'
    AND z.prov_tax_id = p.prov_tax_id)
    THEN 'Non-Objecting Bilateral Physicians'
    WHEN EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'More Research Needed'
    AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'More Research Needed'
    WHEN EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Objector' AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'ERROR'
    else 'Market Review/Preparing to Mail'
    END AS [Updated Bucket]
    ,COALESCE(q.INDdesc, f.IND_desc) AS INDdesc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,'' AS OrderedRank
    INTO SQS_Bucketed_Details_SMG_on_SMGXXX
    From #SQS_EDW_SOURCE_WithSMG z
    left join #F f ON f.PROV_TAX_ID = z.PROV_TAX_ID
    AND z.SYSTEMNAME = f.SYSTEM_NAME
    AND z.PROVIDERNAME = f.Provider
    Left join #Q q ON z.PROV_TAX_ID = q.TIN
    GROUP BY z.SYSTEMNAME
    --,Z.[SubsystemName]
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,q.INDdesc
    ,f.IND_Desc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,z.LCLM_RSTMT_TREND_CAT_CD
    As I am a developer I do not have the access to Sql profiler or tuning agent to optimize my query, I have used some joins over the temp table #HIHO which indeed pulling the records from table EDW_Source which has 5 million records, I also added Non clustered
    indexes on prov_ID, SMG_ID and Incurred month for this table, but still it is taking longer time. Need help

    Hi, It needs some more tweaks but pls try this one
    USE
    Go
    --****Create sqs_objector_TINs (Objections and Rejections)****
    --Drop table .dbo.sqs_objector_TINs
    select distinct a.TIN as Prov_TIN
    Into #sqs_objector_TINs
    from .dbo.sqs_provider_tracking as a with (nolock)
    where a.[Objector?] in ('Top Objector','Objector','Rejector')
    /*********** Query for SQS_TINtoSyst***********/
    --DROP TABLE .dbo.SQS_TINtoSystem
    select distinct
    b.SRC_PROV_ID
    --,case
    -- when a.SYSTEM_NAME is null
    -- then
    -- case
    -- when a.CTRCT_GRP_NAME is null
    -- then a.PROV_SMG_NAME
    -- else a.CTRCT_GRP_NAME
    -- end
    -- else a.SYSTEM_NAME
    --end as SYSTEM_NAME
    ,COALESCE(a.SYSTEM_NAME, a.CTRCT_GRP_NAME, a.PROV_SMG_NAME) AS SYSTEM_NAME
    INTO #SQS_TINtoSystem
    from
    PARE.dbo.EDW_PROD_HOSPITAL_MASTER a with (nolock)
    Inner Join PARE.dbo.EDW_PROD_HOSPITAL_ID_XREF b with (nolock)
    on a.SMG_ID = b.SMG_ID
    -- Inner Join .dbo.SQS_EDW_Source q
    --on b.SRC_PROV_ID = q.PROV_TAX_ID
    where b.SRC_PLATFORM_CD = 'TX'
    and exists
    select
    SMG_ID
    from PARE.dbo.EDW_PROD_HOSPITAL_ID_XREF as t1 with (nolock)
    where SRC_PLATFORM_CD = 'TX'
    and exists (select q.PROV_TAX_ID from .dbo.SQS_EDW_Source q with (nolock) where q.PROV_TAX_ID = b.SRC_PROV_ID)
    and a.SMG_ID = t1.SMG_ID
    /************** Query for SQS_Bucketed_Details_SMG*****************/
    DROP TABLE .dbo.SQS_Bucketed_Details_SMG
    --Create temp table
    SELECT z.SYSTEMNAME
    ,Z.PROV_TAX_ID
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.SRC_PAR_CD
    ,z.SEQUEST_AMT
    ,case when Z.LCLM_RSTMT_TREND_CAT_CD IN ('HI','HO') Then 'H' else 'P' end as Hosp_Ind
    ,Z.SMG_ID
    INTO #SQS_EDW_SOURCE_WithSMG
    FROM dbo.SQS_EDW_SOURCE_WithSMG z with (nolock)
    WHERE (Z.Incurred_Mth >= convert(datetime,'01/01/2013')) and (Z.Incurred_Mth < convert(datetime, '1/1/2014'))
    --between convert(datetime,'01/01/2013') and convert(datetime, '12/31/2013 23:59:59.996')
    --YEAR(Z.Incurred_Mth)=2013
    -- Create Temp table Q
    select
    x.TIN,
    case when max(x.IND) = 'NYN'
    then 'Standard'
    when max(x.IND) = 'YNN'
    then 'Express'
    when max(x.IND) = 'NNY'
    then 'Non_Standard' else 'Mixed'
    end as INDdesc
    Into #Q
    FROM
    (SELECT
    a.tin,
    MAX(a.express) + MAX(a.StandardInd) + MAX(NonstandardIND) as IND
    from
    (select r.TIN,
    case when MAX(r.Express) like 'Y%' then 'Y' else 'N' end As Express,
    case when MAX(r.Standard) = 'Y' then 'Y' else 'N' end As StandardInd,
    case when MAX(r.[Non-Standard]) = 'Y' then 'Y' else 'N' end AS NonstandardIND
    FROM DBO.SQS_Objectors_01032014 r with (nolock)
    GROUP BY r.TIN) a
    group by a.TIN) x
    group by x.TIN
    --Create Temp table F
    Select *
    INTO #F
    FROM(
    SELECT distinct g.prov_tax_id
    ,g.system_name
    ,g.provider
    ,case when g.reimburse_mixed = 'Y' then 'Mixed'
    when g.reimburse_express = 'Y' then 'Express'
    when g.reimburse_standard = 'Y' then 'Standard'
    when g.reimburse_NonStandard = 'Y' then 'NonStandard'
    end as IND_Desc
    ,g.Time_Period_for_Dispute
    ,case when g.Renewal_Date = 'N' and g.Expiration_Date = 'N'
    then 'Unclear'
    when g.Renewal_Date = 'N' and g.Expiration_Date <> 'N'
    then 'Termination'
    when g.Renewal_Date <> 'N' and g.Expiration_Date = 'N'
    then 'Evergreen'
    when g.Renewal_Date <> 'N' and g.Expiration_Date <> 'N'
    then 'Termination'
    else 'Unknown'
    end as 'Renew_Term_Ind'
    ,g.Renewal_Date
    FROM
    (select distinct
    bb.PROV_TAX_ID1 as prov_tax_id
    ,aa.*
    from
    [dbo].[Top_600_Hospitals3] aa with (nolock)
    left join pare.dbo.EDW_PROD_HOSPITAL_MASTER bb with (nolock)
    on --a.CTRCT_GRP_NAME = b.CTRCT_GRP_NAME
    aa.Provider = bb.PROV_SMG_NAME
    -- and (a.SYSTEM_NAME = b.SMG_SYS_NAME or a.SYSTEM_NAME = b.SYSTEM_NAME)
    --and a.ADDR_LINE1 = b.ADDR_LINE1
    and aa.STATE_CD = bb.STATE_CD
    --and a.ZIP_CD = b.ZIP_CD
    and aa.City1 = bb.CITY_NAME
    where aa.SYSTEM_NAME <> 'SEE ABOVE') g
    where g.system_name <> 'SEE ABOVE') h
    where h.ind_Desc is not null
    SELECT DISTINCT z.PROV_TAX_ID
    , z.SMG_ID
    INTO #HIHO_Records
    FROM SQS_EDW_SOURCE_WithSMG z with (nolock)
    WHERE z.LCLM_RSTMT_TREND_CAT_CD IN ('HO', 'HI')
    AND Z.Incurred_Mth >=convert(datetime, '1/1/2013') and Z.Incurred_Mth <convert(datetime, '1/1/2014')
    --YEAR(Z.Incurred_Mth)=2013
    ---------------------------------Load Dataset into Temp table---------------
    SELECT
    z.SYSTEMNAME
    --,Case when ZXC.[Subsystem Name] <> 'NULL' Then zxc.[SubSystem Name]
    --else NULL
    --End AS SubSystemName
    , CASE
    WHEN z.PROV_TAX_ID IN
    (SELECT zxc.TIN
    FROM dbo.SQS_Provider_Tracking zxc with (nolock)
    WHERE zxc.[SubSystem Name] <> 'NULL'
    THEN
    (SELECT top 1 [Subsystem Name]
    FROM dbo.SQS_Provider_Tracking zxc with (nolock)
    WHERE z.PROV_TAX_ID = zxc.TIN)
    End As SubSYSTEMNAME
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,SUM(z.SEQUEST_AMT) Actual_Sequestered_Amt
    , CASE
    WHEN z.SRC_PAR_CD IN ('E','O','S','W')
    THEN 'Nonpar Waiver'
    -- --Is Puerto Rico of Lifesynch
    WHEN z.PROV_TAX_ID IN
    (SELECT a.PROV_TAX_ID
    FROM .dbo.SQS_NonPar_PR_LS_TINs a with (nolock)
    WHERE a.Bucket <> 'Nonpar'
    THEN
    (SELECT top 1 a.Bucket
    FROM .dbo.SQS_NonPar_PR_LS_TINs a with (nolock)
    WHERE a.PROV_TAX_ID = z.PROV_TAX_ID)
    --**Amendment Mailed**
    WHEN z.PROV_TAX_ID IN
    (SELECT b.PROV_TIN
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    where not exists (select * from dbo.sqs_objector_TINs t with (nolock) where b.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN
    (SELECT top 1 b.Mailing
    FROM dbo.SQS_Mailed_TINs_010614 b with (nolock)
    WHERE z.PROV_TAX_ID = b.PROV_TIN
    -- --**Amendment Mailed Wave 3-5**
    WHEN z.PROV_TAX_ID In
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (3rd Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (3rd Wave)'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (4th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (4th Wave)'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (5th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (5th Wave)'
    -- --**Top Objecting Systems**
    WHEN z.SYSTEMNAME IN
    ('ADVENTIST HEALTH SYSTEM','ASCENSION HEALTH ALLIANCE','AULTMAN HEALTH FOUNDATION')
    THEN 'Top Objecting Systems'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Top Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H'
    THEN 'Top Objecting Systems'
    -- --**Other Objecting Hospitals**
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H')
    THEN 'Other Objecting Hospitals'
    -- --**Objecting Physicians**
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    obj.TIN
    FROM .dbo.SQS_Provider_Tracking obj with (nolock)
    WHERE obj.[Objector?] in ('Objector','Top Objector')
    and z.PROV_TAX_ID = obj.TIN
    and z.Hosp_Ind = 'P')
    THEN 'Objecting Physicians'
    --****Rejecting Hospitals****
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H')
    THEN 'Rejecting Hospitals'
    --****Rejecting Physciains****
    WHEN
    (z.PROV_TAX_ID IN
    (SELECT
    obj.TIN
    FROM .dbo.SQS_Provider_Tracking obj with (nolock)
    WHERE z.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector')
    and z.Hosp_Ind = 'P')
    THEN 'REjecting Physicians'
    ----**********ALL OBJECTORS SHOULD HAVE BEEN BUCKETED AT THIS POINT IN THE QUERY**********
    -- --**Non-Objecting Hospitals**
    WHEN z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    WHERE
    (z.PROV_TAX_ID = h.PROV_TAX_ID)
    OR h.SMG_ID IS NOT NULL)
    and z.Hosp_Ind = 'H'
    THEN 'Non-Objecting Hospitals'
    -- **Outstanding Contracts for Review**
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz with (nolock)
    where qz.Mailing = 'Non-Objecting Bilateral Physicians'
    AND z.PROV_TAX_ID = qz.PROV_TIN)
    Then 'Non-Objecting Bilateral Physicians'
    When z.prov_tax_id in
    (select
    p.prov_tax_id
    from dbo.SQS_CoC_Potential_Mail_List p with (nolock)
    where p.amendmentrights <> 'Unilateral'
    AND z.prov_tax_id = p.prov_tax_id)
    THEN 'Non-Objecting Bilateral Physicians'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'More Research Needed'
    AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'More Research Needed'
    WHEN z.PROV_TAX_ID IN (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz with (nolock) where qz.Mailing = 'Objector' AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'ERROR'
    else 'Market Review/Preparing to Mail'
    END AS [Updated Bucket]
    ,COALESCE(q.INDdesc, f.IND_desc) AS INDdesc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,'' AS OrderedRank
    INTO dbo.SQS_Bucketed_Details_SMG with (nolock)
    From #SQS_EDW_SOURCE_WithSMG z
    left join #F f ON f.PROV_TAX_ID = z.PROV_TAX_ID
    AND z.SYSTEMNAME = f.SYSTEM_NAME
    AND z.PROVIDERNAME = f.Provider
    Left join #Q q ON z.PROV_TAX_ID = q.TIN
    GROUP BY z.SYSTEMNAME
    --,Z.[SubsystemName]
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,q.INDdesc
    ,f.IND_Desc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,z.Hosp_Ind
    /************************** Drop temp tables*********************/
    --DROP TABLE #SQS_EDW_SOURCE_WithSMG
    --DROP TABLE #Q
    --DROP TABLE #F
    --DROP TABLE #HIHO_Records
    --DROP TABLE #SQS_TINtoSystem
    --DROP TABLE #SQS_EDW_SOURCE_WithSMG
    --DROP TABLE #sqs_objector_TINs

  • Connecting Power Query to SharePoint Foundation 2010

    I'm looking to set up PowerQuery in Excel 2013 to link into the various lists on our SharePoint 2010 Foundation server.
    I have established the connection URL.
    The SharePoint Foundation 2010 server is on the same LAN I'm connected to, so I've opted for Windows Authentication.
    These two aspects of the setup appear to be fine: However at the point when Power Query links to the SharePoint server the following error is being returned.
    DataSource.Error: OData: The feed's metadata document appears to be invalid.
    Any ideas?

    Hi,
    We have forum for Power Query discussion and feedback. I will move your post to that forum:
    https://social.technet.microsoft.com/Forums/en-us/home
    The reason why I move your post is to get you the most qualified pool of respondents, and other partners who read the forums
    regularly can either share their knowledge or learn from your interaction with us.
    Thank you for your understanding.

  • How to get the recordcount of a query in a array

    I have an array called "sums" that holds 4 query's, each
    query has a different number of records.
    Then i use this code to loop the records of the query inside
    the array:
    <cfloop index="x" from="1" to="#arrayLen(sums)#">
    <cfloop index="i" from="1" to="#sums[x].recordcount#">
    data to loop
    </cfloop>
    </cfloop>
    This results in 4 times 4 records, of course as i now use the
    array length in the inner loop.
    My question is, how can i get the recordcount of a query in a
    array so i can use that for the inner loop "to" value.
    Thanks.

    quote:
    Originally posted by:
    MarcovandenOever
    Does sums[x]recordcount point to the first query in the array
    sums when i use it like this?
    In the array there are four query's, i want to loop the
    array, then i want to loop the records of each query.
    <cfloop index="x" from="1" to="#arrayLen(sums)#">
    <cfloop index="i" from="1" to="#sums[x].recordcount#">
    data to loop
    </cfloop>
    </cfloop>
    No. It points to each query in turn. So if you have four
    queries, the first time it will point to sum[1]. Then next time
    sum[2], etcetera. It should work exactly the way you want "as is".
    If you are having a problem, it is probably related to the code
    inside your inner loop.

  • Very Slow Query due to Bitmap Conversion

    I have a strange problem with the performance of a spatial query. If I perform a 'SELECT non_geom_column FROM my_table WHERE complicated_join_query' the result comes back sub-second. However, when I replace the column selected with geometry and perform 'SELECT geom_column FROM my_table WHERE same_complicated_join_query' the response takes over a minute.
    The issue is that in the second case, despite the identical where clause, the explain plan is significantly different. In the 'select geom_column' query there is a BITMAP CONVERSION (TO ROWIDS) which accounts for all of the extra time, where as in the 'select other_column' query that conversion is replaced with TABLE ACCESS (BY INDEX ROWID) which is near instant.
    I have tried putting in some hints, although I do not have much experience with hints, and have also tried nesting the query in various sub-selects. Whatever I try I can not persuade the explain plan to drop the bitmap conversion when I select the geometry column. The full query and an explanation of that query are below. I have run out of things to try, so any help or suggestions at all would be much appreciated.
    Regards,
    Chris
    Explanation and query
    My application allows users to select geometries from a map image through clicking, dragging a box and various other means. The image is then refreshed - highlighting geometries based on the query with which I am having trouble. The user is then able to deselect any of those highlighted geometries, or append others with additional clicks or dragged selections.
    If there are 2 (or any even number of) clicks within the same geometry then that geometry is deselected. Alternatively the geometry could have been selected through an intersection with a dragged box, and then clicked in to deselect - again an even number of selections. Any odd number of selections (i.e. selecting, deselecting, then selecting again) would result in the geometry being selected.
    The application can not know if the multiple user clicks are in the same geometry, as it simply has an image to work with, so all it does is pass all the clicks so far to the database to deal with.
    My query therefore does each spatial point or rectangle query in turn and then appends the unique key for the rows each returned to a list. After performing all of the queries it groups the list by the key and the groups with an odd total are 'selected'. To do this logic in a single where clause I have ended up with nested select statements that are joined with union all commands.
    The query is therefore..
    SELECT
    --the below column (geometry) makes it very slow...replacing it with any non-spatial column takes less than 1/100 of the time - that is my problem!
    geometry
    FROM
    my_table
    WHERE
    primary_key IN
    SELECT primary_key FROM
    SELECT primary_key FROM my_table WHERE
    sdo_relate(geometry, mdsys.sdo_geometry(2003, 81989, NULL, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array( rectangle co-ords )), 'mask=anyinteract') = 'TRUE'
    UNION ALL SELECT primary_key FROM my_table WHERE
    sdo_relate(geometry, mdsys.sdo_geometry(2001, 81989, sdo_point_type( point co-ords , NULL), NULL, NULL), 'mask=anyinteract') = 'TRUE'
    --potentially more 'union all select...' here
    GROUP BY primary_key HAVING mod(count(*),2) = 1     
    AND
    --the below is the bounding rectangle of the whole image to be returned
    sdo_filter(geometry, mdsys.sdo_geometry(2003, 81989, NULL, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array( outer rectangle co-ords )), 'mask=anyinteract') = 'TRUE'

    Hi
    Thanks for the reply. After a lot more googling- it turns out this is a general Oracle problem and is not solely related to use of the GEOMETRY column. It seems that sometimes, the Oracle optimiser makes an arbitrary decision to do bitmap conversion. No amount of hints will get it to change its mind !
    One person reported a similarly negative change after table statistic collection had run.
    Why changing the columns being retrieved should change the execution path, I do not know.
    We have a numeric primary key which is always set to a positive value. When I added "AND primary_key_column > 0" (a pretty pointless clause) the optimiser changed the way it works and we got it working fast again.
    Chris

  • Mapping Access 2010 Query Expressions In Crystal Reports

    Hello,
    I am new to Crystal Reports.
    When I change the datasource of a Crystal report to an Access 2010 query that has an expression in it, it is not able to map that calculated field. The expression in question is a simple iif statement that yields a yes or no, given the condition that's met. It works fine in Access and is very basic.
    But I can't get it to map in Crystal - so I tested it by changing the expression in Access to defect:"x" - even simpler. It still shows up in Crystal as unmapped when I point to the query and hit the Crystal update button.
    Can Crystal map expressions in an Access 2010 query, or does it just handle straight table fields that occur in a table or query?
    Regards,
    Dan

    Hello Dan,
    When pointing your report from one data source, to another one, the reason it does not initially map the field, it is because they are seen as defined with different data type. One is defined with 255 characters, and the other one is seen as a Memo. In the "Map Fields" window, uncheck  the option "Match type", and you will then be able to map your expression field manually.
    Note that the MS Access provider, send the information to Crystal Reports regarding the data type, and the fact it is different, it is because the provider used send different information to Crystal Reports, and if a field is defined with more than 255 characters, it will be seen as a memo field.
    There is nothing that can be done in Crystal Reports to change the data type as it is provided by the database provider.
    By design, it does not list a memo field as a database field you can group by, because large string generally contains a description, comments, ... and this type of information is generally always different, so there is no reason to group by those field with that data type.
    Having said that, it is possible to group by a formula that contains the memo field to give the flexibility to bring back a portion of the characters that the memo field contains. To do so:
    1. Create a formula that uses the memo field like:
         {Database.MemoField}   
    2. Save and close the formula.
    3. Under the menu "Insert", select "Group"
    4. In the "Insert Group" window, select the formula created in the previous
    steps to group by.
    This information is available in the SAP Knowledge Base Article:
         1214731 - Unable to group on a memo field in Crystal Reports
    I hope the above information answered your questions.
    Patrick

  • Can I use multiline SQL commands in a query (within a component)?

    I would like to modify the following query:
    <td>ItranslationString</td>
         <td>
         INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (?, ?, ?, 'N', ?)
         </td>
         <td>daKeyField varchar
         daLanguageField varchar
         daTranslationField varchar
         StringTranslationFilename varchar
         </td>
    so that the daSourceFile a) is selected from another record, if it exists b) uses the constant, if not.
    In SQL Command the commands (without placeholders) look:
    declare c integer;
    res varchar(30);
    key_var varchar(100);
    def_lang_var varchar(5);
    begin
    key_var := 'newString';
    def_lang_var := 'en';
    res := 'ap_string.htm';
    select count(*) into c FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    if c > 0 then
    select daSourceFile into res FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    end if;
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (key_var, 'cs', 'translation', 'N', res);
    end;
    However, such a query does not work in the query resource (multiline commands cannot be used?).
    Neither can I think of one line query that would provide the same functionality (tried to test with COALESCE).

    Yes, I got the point. The query looks like:
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile)
    SELECT daKey, daLanguage, daTranslation, daStringFlag, daSourceFile FROM (
    select 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, daSourceFile FROM TRANSLATIONSTRINGS WHERE daKey = 'newString1' AND daLanguage = 'cs' UNION ALL SELECT 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, 'default' daSourceFile FROM DUAL)
    WHERE rownum<=1;
    so that's the way how to solve it via SQL.
    (Since I can't use DECLARE, I need to bind entry parameters as many times as they appear in the query - not a very nice way, but it works).
    The question still is, whether there is a way how to use a multiline query in Component Queries. Even though it is not mentioned specifically in the documentation, it seems it is NOT to be possible by design. So the real question is really WHY - I guess it would be a little bit more convenient to begin/commit transactions, use variables, etc. in a multiline query.
    Yet, Sam, thanks!

  • Slow query - db_cache_size ?

    Hi,
    Oracle 9.2.0.5.0 ( solaris )
    I've got a query which when run on a production machine runs very slow ( 10 hours ), but on a preproduction machine ( with same data ) takes about a 10th of the time. I have confirmed that on both machines we are getting the same plan.
    The only thing I can nail it down to, is that in production I'm seeing lots more "db file sequential read" wait events. Can I assume this is due to the blocks not being in/staying in the cache?
    When running on preprod, the hit ratio for the query is .90 + , on production it drops down to .70 - .80 ( as per query below )
    I have plenty of memory available on the machine, would it be wise to size up the caches? db_cache_size, db_keep_cache_size, db_recycle_cache_size ?
       SELECT (P1.value + P2.value - P3.value) / (P1.value + P2.value)
         FROM   v$sesstat P1, v$statname N1, v$sesstat P2, v$statname N2,
                v$sesstat P3, v$statname N3
         WHERE  N1.name = 'db block gets'
         AND    P1.statistic# = N1.statistic#
         AND    P1.sid = &sid
         AND    N2.name = 'consistent gets'
         AND    P2.statistic# = N2.statistic#
         AND    P2.sid = P1.sid
         AND    N3.name = 'physical reads'
         AND    P3.statistic# = N3.statistic#
         AND    P3.sid = P1.sid
    PRE-PRODUCTION
      call     count       cpu    elapsed       disk      query    current        rows   
      Parse        1      0.64       0.64          0          0          0           0      
      Execute      1      0.00       0.00          0          0          0           0      
      Fetch        2    186.92     329.88     162174    5144281          5           1      
      total        4    187.56     330.53     162174    5144281          5           1      
      Elapsed times include waiting on following events:
        Event waited on                             Times   Max. Wait  Total Waited
        ----------------------------------------   Waited  ----------  ------------
        SQL*Net message to client                       2        0.00          0.00
        db file sequential read                    160098        1.44        162.52
        db file scattered read                          1        0.00          0.00
        direct path write                              27        0.66          3.36
        direct path read                               97        0.00          0.02
        SQL*Net message from client                     2      985.79        985.79
    PRODUCTION
      call     count       cpu    elapsed       disk      query    current        rows
      Parse        1      2.41       2.34         79         16          0           0  
      Execute      1      0.00       0.00          0          0          0           0  
      Fetch        2    844.76   12305.06    1507519    5226663          0           1  
      total        4    847.17   12307.41    1507598    5226679          0           1  
      Elapsed times include waiting on following events:
        Event waited on                             Times   Max. Wait  Total Waited
        ----------------------------------------   Waited  ----------  ------------
        SQL*Net message to client                       2        0.00          0.00
        db file sequential read                   1502104        4.40      11849.13
        direct path write                             361        0.57          3.06
        direct path read                              361        0.05          0.88
        buffer busy waits                              36        0.02          0.17
        latch free                                      5        0.01          0.01
        log buffer space                                2        1.00          1.37
        SQL*Net message from client                     2      687.95        687.95
      Suggestions for further investigation more than welcome.

    user12044475 wrote:
    Hi,
    Oracle 9.2.0.5.0 ( solaris )
    I've got a query which when run on a production machine runs very slow ( 10 hours ), but on a preproduction machine ( with same data ) takes about a 10th of the time. I have confirmed that on both machines we are getting the same plan.
    The only thing I can nail it down to, is that in production I'm seeing lots more "db file sequential read" wait events. Can I assume this is due to the blocks not being in/staying in the cache?
    There are more physical reads, and the average read time is longer. This may simply be a reflection of the fact that other people are working on the production database at the same time and (a) kicking your data out of the cache and (b) causing you to queue at the disc as they do their I/O. A larger cache MIGHT protect your data a little longer, and MAY reduce their I/O at the same time so that the I/Os are faster - but we have no idea what side effects might then appear.
    It's also worth considering whether you did something as you tranferred the data from production to pre-production that helped to improve query performance. (As a simple example, an export/import could have eliminated a lot of row migration - and the nature of your plan means you MIGHT be suffering a lot of excess I/O from "table fetch continued row"). So, how did you get the data from production to test, how long ago, what's happened to it since, and do you have any session statistics taken as you ran the two queries ?
    Since your execution plan (prediction) is a long way off the actual run time, though, (even on the pre-production system), it's probably more important to work out whether you can make your query much more efficient before you make any dramatic changes to the system. I notice that you have three existences subqueries that appear at the end of the plan - such subqueries wreck the optimizer's arithmetic in your version of Oracle and can make it do very silly things. (See for example this blog note: http://jonathanlewis.wordpress.com/2006/11/08/subquery-selectivity )
    The effect of the subqueries may (for example) be why you have a full tablescan on the second table in a nested loop join at one point in your query. The expectation of a vastly reduced number of rows may be why you are seeing nested loops all over the place when (possibly) a couple of hash joins would be more appropriate.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
    +"I believe in evidence. I believe in observation, measurement, and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wilder and more ridiculous something is, however, the firmer and more solid the evidence will have to be."+
    Isaac Asimov                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Vendor payment list

    Hi Experts my client want to see the vendors payment history on the monthly wise ( or selected months)  .. is FBL1N is fine to see the vendor payment history by selecting cleared items....?? or any other SAP Standard report available .... please shar

  • Unable to open applications: error code -10810

    For some reason I have started to have problems opening up applications after my computer has been on for around 10 minutes. I am able to open up apps at startup, but after they've been running for a while, if I try to open additional apps (from eith

  • Variable VMARGS is undefined

    Hello, i have a coldfusion 8.0.1 multi-instance installation, but one of our 4 instance, from about a week, has a strange behaviour when i click on the "Settings Summary" in the CFIDE administration console.. it start to print out all the summary inf

  • Random tabs zoom in to max, connot be resized, have to close

    Of a number of open tabs, some of them "zoom in" to max and when I press "zoom out", it does, then immediately zooms back in. Only "cure" is to close the tab. Just now, one tab was"bouncing" between normal and zoomed in and I could not close it. Had

  • MSI P67A-C43 problems

    Hey everyone. I recently bought a MSI P67A-C43 using a Intel i5 2500K and everything has been working great until recently. I realized it has a post beep every time you turn it on, which is the short beeps followed by a 5th beep and everything starts