Find latest value based on defined date
Hi all,
In my below example, I want to find the latest symptom and name which has been added after 24-mar-2012 (not before that) .Not getting proper output
with xx as
(select 101 as ID, 'A01' as name, '03/24/2012' as create_date from dual
union all
select 101, 'A01', '03/24/2012' from dual
union all
select 102 , 'A02', '03/24/2012' from dual
union all
select 101 , 'A01', '03/30/2012' from dual
union all
select 102 , 'A02', '03/30/2012' from dual
union all
select 102 , 'A01', '04/21/2012' from dual
union all
select 101 , 'A01','04/22/2012' from dual
xy as
(select 101 as ID, 'asthma' as symptom from dual
union all
select 101 , 'cancer' from dual
union all
select 101 , 'bpressure' from dual
union all
select 102, 'sbp' from dual
union all
select 101 , 'dbp' from dual
union all
select 102, 'allergy' from dual
union all
select 103 , 'cardiac failure' from dual
union all
select 102 , 'sneezing' from dual
select xx.name, xy.symptom, xx.create_date from xx, xy
where xx.id=xy.id
group by xx.name, xy.symptom, xx.create_date
having xx.create_date >'03/24/2012'
Costa wrote:
Hi all,
In my below example, I want to find the latest symptom and name which has been added after 24-mar-2012 (not before that) .Not getting proper outputwhat does the proper output look like according to you?
1 with xx as
2 (select 101 as ID, 'A01' as name, '03/24/2012' as create_date from dual
3 union all
4 select 101, 'A01', '03/24/2012' from dual
5 union all
6 select 102 , 'A02', '03/24/2012' from dual
7 union all
8 select 101 , 'A01', '03/30/2012' from dual
9 union all
10 select 102 , 'A02', '03/30/2012' from dual
11 union all
12 select 102 , 'A01', '04/21/2012' from dual
13 union all
14 select 101 , 'A01','04/22/2012' from dual
15 ),
16 xy as
17 (select 101 as ID, 'asthma' as symptom from dual
18 union all
19 select 101 , 'cancer' from dual
20 union all
21 select 101 , 'bpressure' from dual
22 union all
23 select 102, 'sbp' from dual
24 union all
25 select 101 , 'dbp' from dual
26 union all
27 select 102, 'allergy' from dual
28 union all
29 select 103 , 'cardiac failure' from dual
30 union all
31 select 102 , 'sneezing' from dual
32 )
33 select xx.name, xy.symptom, xx.create_date from xx, xy
34 where xx.id=xy.id
35 group by xx.name, xy.symptom, xx.create_date
36* having xx.create_date >'03/24/2012'
SQL> /
NAM SYMPTOM CREATE_DAT
A01 cancer 04/22/2012
A01 bpressure 04/22/2012
A01 bpressure 03/30/2012
A01 allergy 04/21/2012
A01 asthma 03/30/2012
A01 sbp 04/21/2012
A01 sneezing 04/21/2012
A02 sneezing 03/30/2012
A01 asthma 04/22/2012
A01 cancer 03/30/2012
A02 sbp 03/30/2012
NAM SYMPTOM CREATE_DAT
A01 dbp 04/22/2012
A01 dbp 03/30/2012
A02 allergy 03/30/2012
14 rows selected.
SQL>
Similar Messages
-
Is it possible to find the table based on the Date ?
Dear Team ,
Is it possible to find the table based on the Date ?
I have created an table ,But forgot the Table Name .
Is it possible to find the Tables created on particular Date .
Regards ,
Augustineas date is record the time also below query will work.
select * from user_objects
where
object_type = 'TABLE' and
to_date(created,'DD-MON-YYYY') =to_date('<your date value in DD-MON-YYYY format>','DD-MON-YYYY');
Edited by: shaileshM on Feb 24, 2010 9:39 PM -
Get Old Value and the new value based on the date
Hi
I have a table called roster created below with following insert statements.
CREATE TABLE ROSTER
ROSTER_EMPLOYEE_DEF_ID NUMBER,
EMPLOYEE_ID NUMBER,
DEFINITION_REGION_CODE NUMBER,
DEFINITION_DISTRICT_CODE NUMBER,
DEFINITION_TERRITORY_CODE NUMBER,
START_DATE DATE,
END_DATE DATE
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(1,299,222,333,444,'1-JUN-2011','30-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(2,299,223,334,445,'1-JUL-2011','20-JUL-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(3,299,224,335,446,'1-AUG-2011','30-AUG-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(4,300,500,400,300,'1-JUN-2011','20-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(5,300,501,401,301,'1-JUL-2011','20-JUL-2011')
In the above table we have columns like
EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE
The result i am looking from the above table is based on the EMPLOYEE_ID OF START_DATE AND END_DATE
I need to get OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_CODE
Similarly OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_REGION_CODE
and OLD_DEFINITION_TERRITORY_CODE and the NEW_DEFINITION_TERRITORY_CODE
I need to get one row of data for each employee saying old value and new value
for employee 299 there are 3 records it must give the new record which is the latest date i.e start date 1-aug-2011 and end date 30-aug-2011 old record will be
start date 1-jul-2011 and 20-jul-2011
For the above table data i need to get the data as below
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_CODE OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE START_DATE END_DATE
299 223 224 334 335 20-JUL-11 30-AUG-11
300 500 501 400 401 20-JUN-11 20-JUL-11
Please suggest me to get the above result based on the data. Please let me know if my posts are not clear
Thanks
SudhirSELECT EMPLOYEE_ID,
OLD_DEFINITION_REGION_CODE,
NEW_DEFINITION_REGION_CODE,
OLD_DEFINITION_DISTRICT_CODE,
NEW_DEFINITION_DISTRICT_CODE,
OLD_DEFINITION_TERRITORY_CODE,
NEW_DEFINITION_TERRITORY_CODE,
START_DATE,
END_DATE
FROM (
SELECT EMPLOYEE_ID,
ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE DESC) RN,
LAG(DEFINITION_REGION_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_REGION_CODE,
DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE,
LAG(DEFINITION_DISTRICT_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_DISTRICT_CODE,
DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE,
LAG(DEFINITION_TERRITORY_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_TERRITORY_CODE,
DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE,
LAG(END_DATE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) START_DATE,
END_DATE
FROM ROSTER
WHERE RN = 1
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE OLD_DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE OLD_DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE START_DAT END_DATE
299 223 224 334 335 445 446 20-JUL-11 30-AUG-11
300 500 501 400 401 300 301 20-JUN-11 20-JUL-11
SQL> SY. -
Month Year values based on Posting Date
In my super huge extra large InfoCube (0CFM_C10) I got a lot of data. I take Posting Date, some KFG and CalMonth/Year. Unfortinally CalMonth/Year duplicates records, if I drop it off the columns/rows I get valid data by Posting Date.
My question is this - is it possible to create some MonthYear Calculated KFG/field/formula or smthng. based on Posting Date? In other words I need Month/Year in rows/ columns or free characteristics...
Edited by: Gediminas Berzanskis on Mar 18, 2008 10:18 AMDear,
When canceling a payment which was created in previous posting periods,
we get system message "Date deviates from permissible range",so
the workaround is changing back the posting period to the previous one
and try to cancel the payment.
However,another system message pops up when we try to cancel payment
after changing back the posting period,which is the "creation date" or
"posting date".
In this scenario, you should select the second option from the
cancellation options window, which is the 'Creation date'. I would like
to explain more below.
Posting Date- means the posting date of the cancellation document, it's
not the posting date of the incoming payment that you wanna perform the
cancellation. In your case, selecting this 'posting date' option, system
deems that you want to post this cancellation document on its own
posting date.
Creating Date- means the posting date/creation date of the incoming
payment, it makes sense that the system works fine if you select this
option. If you cancel the incoming payment and check the JE generated,
you will find that the posting date of this cancellation document is
actually recorded as the posting date of the incoming payment.
Wish it helps you.If you have any problems,please kindly let me know.
Thanks and best regards,
Apple -
Calculate difference in value based on two date parameters
Hi All,
I have a table and need to calculate the difference in rent amount for a property based on two date parameters.
I have uploaded sample data here:
https://app.box.com/s/pu8oa4f3jhrhm0ylshdz2fuo7541vn4z
Thanks
JagHi jaggy99,
Do you have the knowledge of
Excel Add-In? If you don't have knowledge of C#/VB.NET language and Visual Studio, I don't think Excel Add-In is what you want. As I said previously, your problem is totally about the business logic, we don't provide solution for a complete requirement.
Based on your sample data, I think VBA code is suitable.
If you're not familiar with VBA, please take a look at the MSDN documents for scratch:
Getting Started with VBA in Excel 2010
The steps should be like this:
1. Sort all the records by [Rent Change Date] field
2. Loop throuth the records and find the FromDate and ToDate as well as the corresponding [Rent Charged] field
3. Calculate the difference and save the data into a new range
It's not so hard, please have a try, if you encounter any development problems, you can post in this forum.
Thanks.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to find the Sum based on Like Dates
Hello everyone,
Column 1 contains "Date Sent", Column 2 contains "Dates of Service" and Column 3 contains the payment "Amount" in USD. I want to write a formula that will total up the sum of payment values from column 3 based on the date of payment (Column 1).
Thanks!
JaredHi Jared,
This will do what's illustrated in your example, but has a few restrictions:
The dates must run in ascending order.
To get a total for the last date, a later date (with no corresponding amount) must be entered after the last transaction.
Formula:
Entered in D2, and filled down the rest of column D:
=IFERROR(IF(A3>A2,SUMIF($A,A2,C),""),"")
IFERROR is used to suppress the error message that arises from the formula in D10 referencing a cell in D11.
Regards,
Barry -
Find axis value based on coordinates.
I am trying to create a zoom in function for my chart. In
order to do this, I need to find the values of the y axis at
certain points. Is there anyway to use the y coordinates in order
to find the values on the axis?I am trying to create a zoom in function for my chart. In
order to do this, I need to find the values of the y axis at
certain points. Is there anyway to use the y coordinates in order
to find the values on the axis? -
Choosing a value based on newest date, and newest value
Good Afternoon,
I'm in search of help on a statement Im trying to perform in a Query transform in my ETL. So this is the scenario. I have a Value called SGSGVL which is "CYW" and in our descriptions table for the VALUE CYW we have 3 different Descriptions like Cadium Yellow, Cadium Yellow Paint and CDM Yellow and the date the description was added. What I would like to do is say:
Where in the description table = CYW, select the newest date and the most used value.
I've been told I can use a MAX statement but Im unsure exactly how to perform this in the query transform. Can anyone help? It would be GREATLY appreciated!
Thanks!You won't be able to do what you are asking in one query transform - it is complicated due the fact that you need your "max" to be based on something other than the column you want returned (date and count, versus the description). Essentially, what you need to do is:
QUERY1: value, description, field named REC_CNT with mapping of count(*), field named MAX_DATE with mapping of max(date), group by value and description
QUERY2: reads from QUERY1 --> value, field named MAX_REC which has a mapping such as: max(lpad(REC_CNT,'0',5) || '_' || to_char(date,'YYYYMMDD')), and group by value only
QUERY3: also reads from QUERY1 --> value, description, field named THIS_REC which has mapping such as: lpad(REC_CNT,'0',5) || '_' || to_char(date,'YYYYMMDD'), no group-by
QUERY4: joins QUERY2 and QUERY3 on QUERY2.MAX_REC = QUERY3.THIS_REC. Pull the value and description from QUERY3.
Basically - QUERY2 gives you the list of records which are considered the max, and QUERY3 gives you the full list with the same column to be able to join on, so QUERY4 pulls the descriptions only for the max record.
-Trevor -
X-axis values - Set values based upon constant date
I am creating a line graph. I am plotting based upon date/time. I'd like to use a constant date across the x-axis. IE 8:00, 8:15, 8:30. Within the constant value there could be many points or no points. For example there could be a point at 8:01, 8:02, 8:05 and then a point at 8:35. Along the x-axis the label should remain constant at 8:00, 8:15...
Any ideas?Hi,
use the chart engine for creating your graph. When requiring a horizontal time axis you have to use the chart type TimeScatter.
Download the SAP Chart Designer (SDN - Downloads - WebAS) and see the included pdf document that describes how to structure your data XML.
Demo reports are GRAPHICS_GUI_CE_DEMO and GRAPHICS_IGS_CE_TEST.
Regards, Kai -
Query to get values based on a date range.
11g.
Hi there,
I have a simple requirement(hopefully).
I have a parameter which is basically a count range which when I pass the sql query should fetch the values from a column falling in that range.
My table is item details
Item cost
item1 1
item2 10
item3 20
item4 3
.I have a parameter which I have to pass to this query where items are listed based on the cost.
So I want to select items which cost between 0 -10, 11-20, 21-30 and 31-40
Now I am using Apex to show the count report like
0-10 11- 20 21- 30 31- 40
3 2 0 0
The numbers are hyperlinked and I pass the parameters based on which another report shows the details. So if the user clicks on number 3 in the report. The underlying query would be something like
select * from item_Details where cost between 0 and 10.So I was wondering how do pass the parameter to the sql in the best possible way to get the costs based on the range?
Maybe the parameters should be some code which can be decoded in the SQL?
Any help or suggestions please?
Thanks,
RyanHi,
Try this to pass the parameter in the query...
select * from item_Details where cost between to_number(substr('0-10',0,instr('0-10','-')-1)) and to_number(substr('0-10',instr('0-10','-')+1,length('0-10'));
Regards,
Niha -
I have a report that takes 2 date parameters ("Start Date" and "End Date"). Get fields back based on that criteria....I want to create a formula field that shows me the "Amount" field data that is equal to the "End Date".
How can I do that?
Thanks in Advance!!Hi shaun,
You can take a running total of the date as
Running total name : datecount
Summary Field to Summarize as : yourdatefield
Type of summary : Nth largest
N is : 1
Evaluate
For Each Record
Reset
Never
Now Create a Formula for ur fileld as
if {Command.Yourdate} = {#datecount} then {Command.fieldname}
I hope this solves your problem
Regards,
Pradeep -
Hello,
Has anyone created a parent-child hierarchy using Oracle Warehouse Builder or Analytic Workspace Manager. I am using Oracle 10g Rel2 (and AWM) and OWB 10g Rel2.
The values in the dimension table defines the hierarchy.
I don't see an option of creating a value-based hierarchy in OWB though it is mentioned that it supports this particular hierarchy.
In AWM, I am able to create the hierarchy but when I try to view the data in the dimension it gives an error BIB-9531 Invalid hierarchy specified.
Can you please let me know if I am missing something.
Thanks a lot in advance!
Regards,
MaruthiTo create a value based hierarchy:
define the storage as MOLAP, as a minimum create 2 attributes one for the dimension member (define as business in Identifier column), one for the parent member referenece (define as parent in Identifier column), the hierarchy will have no levels. If you add this dimension into a map, you should have a mapping port for both the dimension member and the parent reference. The dimension will use 'Use natural keys from data source'.
There is an expert for simplifying some of this, not sure on when it will be made available on OTN, it drives the creation of the dimensional objects from tables/views etc.. -
Error when executing a scenario based on Variable type Latest Value
Hi,
I have created two ODI varaible -
1) filename of type as "Historize"
2) id of type as "Historize"
I have 2 Models -
1) One is based on FIle Technology with resource name as #CUSTOMER.filename (dynamic filename) (TARGET)
2) second is based on Oracle technology which contains two relational tables (SOURCE)
I have an interface in which one-to-one mapping is done from source to target.
At the junction of two source tables..i have put a query as "CUSTOMER_PAYMENT.CUSTID=CUSTOMER_DETAILS.CUSTID and CUSTOMER_DETAILS.CUSTID !=(#id)"
Package:
drag and drop two ODI variables , interface
Connect two ODI variable to interface and define the variable type as "Declare Variable" in the package.
Define filename as the firststep.
filename(firststep)-----------------------------
INTERFACE
id---------------------------------------------------
It is working fine with java callout and command prompt. It is not working when i invoke it on desginer.
It gives me error:
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenario.java)
at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
at com.sunopsis.dwg.cmd.e.i(e.java)
at com.sunopsis.dwg.cmd.g.y(g.java)
at com.sunopsis.dwg.cmd.e.run(e.java)
at java.lang.Thread.run(Unknown Source)
Similary when i define the variable type as "Latest Value/Niot Persistent"...giving me same error as above...but working finw with java and command prompt.
Thanks
Edited by: user12420305 on Aug 31, 2010 10:42 PMHi,
My Package contains:
First step : customerid and custFileName
Second step : interface
Type of both the variables in package is "Declare"
customerid : type Alphanumeric - Historize
custFileName : type Alphanumeric - Historize
generate a scenario of the package and execute it.
custFileName : abc.txt customerid : 2
The file is created but it is giving me error for customer id.
Operator Description:
select
CUSTOMER_DETAILS.CUSTID CUSTOMER_ID,
CUSTOMER_DETAILS.LAST_NAME || CUSTOMER_DETAILS.FIRST_NAME CUSTOMERNAME,
CUSTOMER_DETAILS.ADDRESS ADDRESS,
CUSTOMER_PAYMENT.PAYMENTID PAYMENT_ID,
CUSTOMER_PAYMENT.AMOUNT AMOUNT
from ODITEST1.CUSTOMER_DETAILS CUSTOMER_DETAILS, ODITEST1.CUSTOMER_PAYMENT CUSTOMER_PAYMENT
where (1=1)
And (CUSTOMER_PAYMENT.CUSTID=CUSTOMER_DETAILS.CUSTID and CUSTOMER_DETAILS.CUSTID !=(#CUSTOMER.customerid))
Operator Execution:
936 : 42000 : java.sql.SQLException: ORA-00936: missing expression
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
at com.sunopsis.sql.SnpsQuery.executeQuery(SnpsQuery.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenario.java)
at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
at com.sunopsis.dwg.cmd.e.i(e.java)
at com.sunopsis.dwg.cmd.g.y(g.java)
at com.sunopsis.dwg.cmd.e.run(e.java)
at java.lang.Thread.run(Unknown Source)
When i try to execute the scenario from command promt/java callout ..it is working fine.
Thanks. -
Convert data values in columns to another value based on a math formula
ISSUE:
I have a database of emergency incidents with descriptive data and longitude and
latitude. I would like to make a google map out of the information but unfortunately
the X Y coordinates are projected in Florida State Plane West in feet. Google maps
requires WGS84 longitude and latitude in decimal degrees.
PROBLEM:
I have written some code in Transact SQL that will convert the values. But I am at a loss as to how to do the following:
1.) plug in the X Y values from my database using an sql SELECT statement.
2.) apply the formula to convert from State Plane to WGS84 to these X Y values
3.) output the results.
In other words, I have the data and I have the formula, but I am not figuring out how to plug the data into the formula and output the results. I am missing how to tie it all together.
CODE:
DECLARE @Easting DECIMAL(18,10);
--SET @Easting = CAST(I_MapX AS DECIMAL(18,10));
DECLARE @Northing DECIMAL(18,10);
--SET @Northing = CAST(I_MapY AS DECIMAL(18,10));
DECLARE @m2sft DECIMAL(10,10);
SET @m2sft = 1200.0/3937.0;
DECLARE @N0 DECIMAL(3,2);
SET @N0 = 0.0;
DECLARE @E0 DECIMAL(18,11);
SET @E0 = 656166.6666666665;
DECLARE @S0 DECIMAL(12,5);
SET @S0 = 2692050.5001/@m2sft;
DECLARE @K0 DECIMAL(18,18);
SET @K0 = 0.9999411764705882;
DECLARE @a DECIMAL(10,2);
SET @a = 6378137.0/@m2sft;
DECLARE @e DECIMAL(18,17);
SET @e = 0.0818191911198883;
DECLARE @ePrime DECIMAL(18,17);
SET @ePrime = 0.08208852110265381;
DECLARE @r DECIMAL(18,10);
SET @r = 6367449.14577/@m2sft;
DECLARE @V0 DECIMAL(15,12);
SET @V0 = 0.005022893948;
DECLARE @V2 DECIMAL(15,12);
SET @V2 = 0.000029370625;
DECLARE @V4 DECIMAL(15,12);
SET @V4 = 0.000000235059;
DECLARE @V6 DECIMAL(15,12);
SET @V6 = 0.000000002181;
DECLARE @L0 DECIMAL(4,2);
SET @L0 = 82.0;
DECLARE @w DECIMAL(18,10);
SET @w = (@Northing - @N0 + @S0)/(@k0*@r);
DECLARE @of DECIMAL(18,10);
SET @of = @w + (sin(@w)*cos(@w))*(@V0 + @V2*power(cos(@w),2) + @V4*power(cos(@w),4) + @V6*power(cos(@w),6));
DECLARE @Rf DECIMAL(18,10);
SET @Rf = @k0*@a/sqrt((1 - power(@e,2)*power(sin(@of),2)));
DECLARE @EPrime2 DECIMAL(18,10);
SET @EPrime2 = @Easting - @E0;
DECLARE @Q DECIMAL(18,10);
SET @Q = @EPrime2/@Rf;
DECLARE @tf DECIMAL(18,10);
SET @tf = tan(@of);
DECLARE @nf DECIMAL(18,10);
SET @nf = @ePrime*cos(@of);
DECLARE @B2 DECIMAL(18,10);
SET @B2 = -0.5 * @tf * (1 + POWER(@nf,2));
DECLARE @B4 DECIMAL(18,10);
SET @B4 = -1/12*(5 + 3 * POWER(@tf,2) +POWER(@nf,2) * (1-9 * POWER(@tf,2)) - 4 * POWER(@nf,4));
DECLARE @B6 DECIMAL(18,10);
SET @B6 = 1/360*(61 + 90*POWER(@tf,2) + 45*POWER(@tf,4) + POWER(@nf,2)*(46 - 252*POWER(@tf,2) - 90*POWER(@tf,4)));
DECLARE @Latitude DECIMAL(18,10);
SET @Latitude = (@of + @B2*POWER(@Q,2)*(1 + POWER(@Q,2)*(@B4 + @B6*POWER(@Q,2))))*180/(PI());
DECLARE @B3 DECIMAL(18,10);
SET @B3 = -1/6*(1 + 2*POWER(@tf,2) + POWER(@nf,2));
DECLARE @B5 DECIMAL(18,10);
SET @B5 = 1/120*(5 + 28*POWER(@tf,2) + 24*POWER(@tf,4) + POWER(@nf,2)*(6 + 8*POWER(@tf,2)));
DECLARE @B7 DECIMAL(18,10);
SET @B7 = -1/5040*(61 + 662*POWER(@tf,2) + 1320*POWER(@tf,4) + 720*POWER(@tf,6));
DECLARE @L DECIMAL(18,10);
SET @L = @Q*(1 + POWER(@Q,2)*(@B3 + POWER(@Q,2)*(@B5 + @B7*POWER(@Q,2))));
DECLARE @Longitude DECIMAL(18,10);
SET @Longitude = (@L0 - (@L/cos(@of))*180/(PI()))*-1;
SELECT
I_EventNumber
FROM Incident
WHERE I_tTimeDispatch > 'May 7, 2012'
SAMPLE DATA:
Here is some raw data in order to get you started. Please notice the MapX and MapY
coordinates are VARCHAR because they are Florida State Plane projections. The goal is
to take these and turn them into WGS84 longitude and latitude expressed as decimal
degrees to be used in Google maps. NOTE: I can convert from VARCHAR to DECIMAL. I just can't figure out where to plug my database columns into the sql query to output a result.
CREATE TABLE Incidents
I_EventNumber VARCHAR(20)
I_MapY VARCHAR(15)
I_MapX VARCHAR(15)
INSERT INTO Incident
VALUES
(FCW69, 0815312, 0672298)
, (FCW70, 0833311, 0697870)
, (FCW71, 0807747, 0699684)
, (FCW72, 0801252, 0689469)
, (FCW73, 0853491, 0692350)Here's a way to get the results, all as part of a single extensive query (this would probably be more suited for defining a VIEW, where you could join on the input table with the VIEW to incorporate the computed values.
If you instead had a business situation where you might need to execute this logic from many different places, rewriting as a user defined function might be better. Anyway, for the answer plus a demonstration of the power of CROSS APPLY to generate
interim working values...
Create_Sample_Data:
Declare @Incident TABLE
I_EventNumber VARCHAR(20), I_MapY VARCHAR(15), I_MapX VARCHAR(15)
INSERT INTO @Incident
VALUES
('FCW69', '0815312', '0672298')
, ('FCW70', '0833311', '0697870')
, ('FCW71', '0807747', '0699684')
, ('FCW72', '0801252', '0689469')
, ('FCW73', '0853491', '0692350') /* This insert is SQL 2008 syntax only.. do multiple inserts or a UNION for 2005 */
AsQuery:
Select *
from @INCIDENT
Cross Apply
Select
N0 = 0.0,
E0 = 656166.6666666665,
K0 = 0.9999411764705882,
e = 0.0818191911198883,
ePrime = 0.08208852110265381,
V0 = 0.005022893948,
V2 = 0.000029370625,
V4 = 0.000000235059,
V6 = 0.000000002181,
L0 = 82.0,
Easting = CAST(I_MapX AS DECIMAL(18,10)),
Northing = CAST(I_MapY AS DECIMAL(18,10))
) as CAStatic
Cross Apply
Select m2sft = 1200.0/3937.0,
EPrime2 = Easting - E0
) as CAComputed1
Cross Apply
Select S0 = 2692050.5001/m2sft,
r = 6367449.14577/m2sft,
a = 6378137.0/m2sft
) as CAComputed2
Cross Apply
Select
w = (Northing - N0 + S0)/(k0*r)
) as CAComputed4
Cross Apply
Select
[of] = w + (sin(w)*cos(w))*(V0 + V2*power(cos(w),2) + V4*power(cos(w),4) + V6*power(cos(w),6))
) as CAComputed5
Cross Apply
Select
Rf = k0*a/sqrt((1 - power(e,2)*power(sin([of]),2))),
tf = tan([of]),
nf = ePrime*cos([of])
) as CAComputed6
Cross Apply
Select
Q = EPrime2/Rf,
B2 = -0.5 * tf * (1 + POWER(nf,2)),
B4 = -1/12*(5 + 3 * POWER(tf,2) +POWER(nf,2) * (1-9 * POWER(tf,2)) - 4 * POWER(nf,4)),
B6 = 1/360*(61 + 90*POWER(tf,2) + 45*POWER(tf,4) + POWER(nf,2)*(46 - 252*POWER(tf,2) - 90*POWER(tf,4)))
) as CAComputed7
Cross Apply
Select
Latitude = ([of] + B2*POWER(Q,2)*(1 + POWER(Q,2)*(B4 + B6*POWER(Q,2))))*180/(PI()),
B3 = -1/6*(1 + 2*POWER(tf,2) + POWER(nf,2)),
B5 = 1/120*(5 + 28*POWER(tf,2) + 24*POWER(tf,4) + POWER(nf,2)*(6 + 8*POWER(tf,2))),
B7 = -1/5040*(61 + 662*POWER(tf,2) + 1320*POWER(tf,4) + 720*POWER(tf,6))
) as CAComputed8
Cross Apply
Select
L = Q*(1 + POWER(Q,2)*(B3 + POWER(Q,2)*(B5 + B7*POWER(Q,2))))
) as CAComputed9
Cross Apply
Select
Longitude = (L0 - (L/cos([of]))*180/(PI()))*-1
) as CAComputedLatLong
Notice that each subsequent CROSS APPLY depends on a "working value" column being defined in some previous cross apply, or the working query. There are a few other options, such as leaving off the very last Cross Apply, and computing Longitude as part
of the main query at the beginning, but it works either way.
EDIT: P.S. - By the way, this query is based on the formula in the original poster's query. My formula matches that formula, and I bet it's right (as far as the lat/long conversion), but it could be the formula for Soylent Green, and I wouldn't know any
better... :-) -
'Value too large for defined data type' error while running flexanlg
While trying to run flexanlg to analyze my access log file I have received the following error:
Could not open specified log file 'access': Value too large for defined data type
The command I was running is
${iPLANET_HOME}/extras/flexanlg/flexanlg -F -x -n "Web Server" -i ${TMP_WEB_FILE} -o ${OUT_WEB_FILE} -c hnrfeuok -t s5m5h5 -l h30c+5 -p ctl
Which should generate a html report of the web statistics
The file has approx 7 Million entries and is 2.3G in size
Ideas?I've concatenated several files together from my web servers as I wanted a single report, several reports based on individual web servers is no use.
I'm running iWS 6.1 SP6 on Solaris 10, on a zoned T2000
SunOS 10 Generic_118833-23 sun4v sparc SUNW,Sun-Fire-T200
Cheers
Chris
Maybe you are looking for
-
When upgrading to Mountain Lion, you are asked to sign in using your iCloud ID. I don't understand how to set up the proper synching of "stuff" if your Mac has multiple user accounts, and they each have their own iCloud ID. The whole issue of suppor
-
Error when test a web service reference
Hello, After creating a web service reference and when i make a test of any method, i get the fowling error: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/200
-
My iPod touch 4th gen won't pick up my right location
When I go onto maps , my iPod isn't picking up my right location , its picking it up across the road. Is there anything I can do?
-
F110 cannot select proposal list
Hi, I'm executing F110, I select as run date today, I can read in the selection "Parameters have been entered". If I try to select from the menu "Proposal" and then "Proposal list", this selection is not possible I cannto understand the reason Could
-
XL Reporter-Security settings in Microsoft Excel prohibit XL Reporter
Hi i am getting the following error when i run the reports in XL Reporter XL Reporter-Security settings in Microsoft Excel prohibit XL Reporter from running. I have made the following chnages 1. Start Microsoft Excel. 2. In the Tools menu, choose Mac