Need SQL to update Column based on latest value
EFF_DTE EXCH_FROM_CTRY_CD EXCH_TO_CTRY_CD SECTY_LST_PRCE SECTY_MTH_AVG_PRCE New Col In View
1/1/2013 USD MXN 12.988 12.988 12.88672
1/2/2013 USD MXN 12.988 12.988 12.88672
1/3/2013 USD MXN 12.9658 12.9806 12.88672
1/4/2013 USD MXN 12.7488 12.92265 12.88672
1/5/2013 USD MXN 12.743 12.88672 12.88672
I have above table and I need to populate New Col using view. New Column value should be Latest date SECTY_MTH_AVG_PRCE . For example If today date is 1/5/2013 date New Col should populate value 12.88672 for all the records for that month only. So every day when new MTH AVG Rate come then it should populate latest value of Secty_MTH_AVG_PRCE to New Col.
The New Col should populate with latest Avg_Prc only for that month. If New Month Start then new col should now update all records value but It should update only for June month Only.
Please help me to make a view query. and let me know if any query?
Thanks in advance.
Hi,
This sounds like a job for the analytic FIRST_VALUE function:
MERGE INTO table_x dst
USING (
SELECT eff_dte
, FIRST_VALUE (secty_mth_avg_price)
OVER (
PARTITION BY exch_from_ctry_cd, exch_to_ctry_cd -- Maybe
ORDER BY eff_dte DESC
) AS new_col
FROM table_x
WHERE eff_dte >= TRUNC (SYSDATE, 'MONTH')
AND eff_dte < ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), 1)
) src
ON ( dst.eff_dte = src.eff_dte
AND dst.exch_from_ctry_cd = src.exch_from_ctry_cd -- Maybe
AND dst.exch_to_ctry_cd = src.exch_to_ctry_cd -- Maybe
WHEN MATCHED THEN UPDATE
SET dst.new_col = src.new_col
;I'm just guessing at lots of things, because the question is so unclear.
Is there a view involved in this problem, as well as the table? What role, if any, do exch_from_ctry_cd and exch_to_ctry_cd play in this problem. When you say "June", do you mean "February"?
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data. Make sure that no column is the same for all rows in the sample data. (E.g., have a least 2 distinct values for exch_to_ctry_cd.)
If you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Similar Messages
-
Hide column based on parameter value
Hi All,
I have requirement where i need to hide one column based on my input parameter value.per example
if my parameter say DISPLAY is Yes then i need to hide the column AMOUNT..
how to achieve this... Please help.
Thanks
BharatHi Bharat,
You can do it following the steps explained in the documentation :
http://docs.oracle.com/cd/E12844_01/doc/bip.1013/e12187/T421739T481157.htm#4535373
regards
Jorge
p.s. If this answers your question then please grant the points and close the thread -
Limit columns based on variable value
Gurus,
My requirement;
User will enter a value "A" in the variable and based on the value i need to limit
the columns in the output. for example in the query designer i have 6 fields in
Rows, in Free Chars i have the field with variable which user will enter. if the value
entered is "A" only 4 fields should appear on the report else if value is "B" only
the other 2 fields should appear.
Is there a way accomplish this...please suggest
Thanks with points in advance...Geni,
Are u using the Excel based Analyzer as your Front End?
If so you can run a small VBA (on event SAPBEXonrefresh) that will hide columns based on the value of the cell that displays the value of the variable that the user is setting.
See code i posted in Re: How do I make cells "0" and not blank for an example.
Is this what you are after?
Hope it helps,
Gili -
Dispaly or Hide a column based on Prompt Value
Hi All,
How can I Display or Hide a Column based on Prompt Value selected?
On my dashboard I have a Report/Request and a Dashboard Prompt.
Dashboard Prompt has three values, say: *'A', 'B' and 'C'*.
And my report/request has three columns named *'Field1', 'Field2'* and Field3'.
What I am trying to achieve is that whenever user selects prompt values as *'A' or 'B'* all the three fields on my report named *'Field1', 'Field2' and Field3'* should be displayed, however whenever user selects prompt values as *'C'* only fields named *'Field1' and 'Field2'* should be displayed.
Thanks,
DeepakHi Bhavna,
I tried using View Selector, however I am not able to achieve the required functionality with that.
I created a Request with 3 columns in it, then I switched to criteria and added another table to that. The new table automatically got the similar 3 columns used in the first report. Now when I tried to delete one of those columns from the new report, it also got deleted from the first report.
All the views are dependent, changes made to one are reflected in other.
Can't figure it out, where am I going wrong?
Thanks,
Deepak -
Inconsistent behaviour of Sybase SQL anywhere update column trigger
Hi, all
I am not sure where to post this issue, since I could not find a forum for Sybase SQL anywhere.
The problem is as follows:
The definition of the update column trigger in help is this:
UPDATE OF column-list
Invokes the trigger whenever a row of the associated table is updated such
that a column in the column-list is
modified.
However, there are cases when the triggers are launched even when the columns are not modified (ie the same exact value is in the both OLD and NEW row)
This happens on BEFORE triggers, never saw it happening on AFTER.
Ways to replicate the problem:
1. Define a before trigger, which fires on update of a specific column in any table.
2. Run an sql which says "update table1 set column1 = column1 where ... "
3. You will see that trigger fires, even though it is not supposed to.
Is this an expected behaviour on "BEFORE" triggers?
ArcadyIf this were a sql server question, then I could tell you that this is by design. A trigger will be executed regardless of the number of rows affected (including zero) and regardless of whether any column in any of the affected rows was changed. I will also point out that PB was designed to work within this design by the inclusion of the [where clause for update/delete] option in the update properties of the datawindow. The idea is that you avoid actual row updates (in the table) where nothing has actually changed (and it also supports collision avoidance).
Based on the history, I would assume that Sybase works exactly the same. -
Update column based on values of same table
I have table T1 with 4 columns 'col1','col2','col3','col4', 'col5','col6' as follows
Col1 Col2 Col3 Col4 Col5 Col6
1111 City1 C AA DDD A1
2222 City 1 DD HHH A1
3333 City2 B EE OOO
4444 City 1 B JJ SSS A1
5555 City2 C KK VVV
6666 City2 RR QQQ
7777 City2 B XX BBB
I have already updated Column 6with value ‘A1’ where Column 2 is ‘City1’.
Now I want to update col 6 where col2 is ‘S’ with following conditions
If Col 3 = ‘B’ then Col6 should be = col4
else it should be = col5SET col6=DECODE(col3,'B',col4,col5)
WHERE col2='S' -
Create a derived column based on a value within the file name
I am importing a CSV file which is easy enough, but I have an issue where I need to manufacture a couple of column values based on the filename of the input. So this same process will import different types of records to the same table in sql server.
I need to pull out the record code from the file name.
For instance, say I can use the same package to input two different CSV files. One is named Input_M02_Data.csv and one named Input_B15_Data.csv. I need to create a derrived column and store the record code there (i.e.: M02 or B15) based
on which file it came out of.
fyi-
I also need to create a second column for Dept based off of the file name as well. M02 is dept 45 and B15 is dept 99 which I also need to insert into this table when I import the data from the .csv file.
Any help is greatly appreciated!Hi Jason,
According to your description, you want to add two derived columns based on the file name to also insert into table. One stores the value between two “_” within file name, another stores the department based on that column.
If in this scenario, we can add a variable FileName that stores the filename, then add the two variables as derived columns like below in the Derived Column Transformation:
Name:
SUBSTRING(@[User::FileName],FINDSTRING(@[User::FileName],"_",1)+1,FINDSTRING(@[User::FileName],"_",2)-(FINDSTRING(@[User::FileName],"_",1)+1))
Dept:
@[User::Name] =="M02"?"dept 45":@[User::Name] =="B15"?"dept 99":"dept 00"
The following screenshot is for your reference:
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
If you have any feedback on our support, please click
here.
Katherine Xiong
TechNet Community Support -
SSRS Matrix report to show or hide year column based on parameter value "Date" selected.
Hey experts!
I have a requirement an ssrs matrix report should display columns (year/s) based on parameter value (date/s).
My Dataset fileds are: Product, Year_name, Month_name, Date
Currently my report output looks like this-
Param Date: 2013-08-01 00:00:0.000
Product +Calender2011 +Calender2012 -Calender 2013........ +Calender2014
Total
Total Jan13 Feb 13 Mar13.. Dec13 Total Total
Abc 100
220
10 20 30....... 20 250 400
Xyz 110
200 50 80 40....... 30 450 600
My requirement: if I'm selecting Date parameter value as '2013-xx-xx' I should only able to see Year column 'Calender2013' and rest of the years should hide. Similarly If I'm selecting Date parameter value as '2014-xx-xx' I should only able to
see Year column 'Calender2014' .
Appreciate your kindly help.
AfanHi Afan,
According to your description, you want to only show the selected year on your report, right?
In this case, you need to get the year from the date parameter using the expression below
=Year(Parameters!Date.Value)
And then use the expression below to get the year from Year_Name field.
=Right(Fields!Year_Name.Value,4)
Then add a filter to the dataset to filter the data like below
Expression:=Year(Parameters!Date.Value)
Operator:=
Value:=Right(Fields!Year_Name.Value,4)
Reference
http://msdn.microsoft.com/en-IN/library/dd255287.aspx
If you have any questions, please feel free to ask.
Regards,
Charlie Liao
TechNet Community Support -
Need to supress main report based on shared value comes from subreport
Hi,
I have a database that is used in both main report and subreport. On main report I have column a,b ,c, d,e,f to display in detail section, the subreport (column c, g,h etc) is also displayed on detail section, the link between main report and subreport is column a,b and a formula based on the value of c. So the link is within one database, some records link with other records and display both matching records on one line(especially column c shows one value in main report and another value in subreport). That's why I need subreport and I can display the report correctly.
Here is my question: if one record in main report couldn't find a match in subreport (subreport is blank), then I would like to show this record; if one record in main report does find a match in subreport, I don't want it to show(need to be supressed). I can define a shared variable to flag whether the subreport is blank or not, but this shared variable has to be placed under the section of subreport in main report and I don't know how to supress the upper detail section with subreport in it.
Any help would be appreciated!
HelenHi
In this case you need to insert the same sub report twise.
Example :
Detail a--Insert the sub report and go in sub report suppress all sections and using shared variables bring the value to main report.
Detail b -- based on detail a sub report suppress the main report records
Detail c-- Your actual sub report will display the values.
Note : use the same links for your detail 'a' sub report which you are using for detail 'c' sub report.
Thanks,
Sastry -
How to retrive new logical column based on flag values in table.
Hi,
i have two tables in rpd
1.file table contains the coulmns------->date,file_count,record_count,cldm_stg,cmsa_stg,archive_stg
2.rejection table columns---------> are same as above
both have same common columns.my requirement is publish a dashboard like:
date | land_files count |alnd_recordscount| target_files count|target_records count|Rejection filecount|rejection record count
These report ineed retrive from those two tables.based on flag values.taget countcomes when all stg values set to ='y'
i.e(cldm_stg='y' and cmsa_stg='y'and archive_stg='y') if not then it will be in rejection file.
Please give solution how to achive my output.
nQSError: 14026] Unable to navigate requested expression: Target_record:[DAggr(FILE_CONTROL.Target_record by [ FILE_CONTROL.FILE_NAME, REJECTED_FILES.FILE_NAME, REJECTED_FILES.NO_OF_ROWS, File_landing.NO_OF_ROWS, File_landing.FILE_LOAD_DATE] SB FILE_CONTROL)]. Please fix the metadata consistency warnings. (HY000)
Edited by: user8767586 on Jan 12, 2010 4:29 AMTanks for ypur reply .only two tables are there named as above.i taken file_control as a fact table.
and i create one new tablecalled target in bmm layer taking logical source as file_control(fact table). and iset the where clause for the new table.and i create a new measure called target_file and target_records.in where clause my query is like
dwbidb."".AUDIT_PROD.FILE_CONTROL.ARCHIVE_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.CMSA_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.LND_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.SCRIPT_STATUS = 'Y' AND dwbidb."".AUDIT_PROD.FILE_CONTROL.STG_STATUS = 'Y'
please tell me if this is right way to achive mt report. and tell me difference between fragmentation and whereclause.for my requrement i ahve to follow which method either fragmentation or whereclause.and in rpd there are no errors and warnings.but in answers i get a follwing error
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14026] Unable to navigate requested expression: TARGET_FILECOUNT:[DAggr(TARGET.TARGET_FILECOUNT by [ TARGET.FILE_NAME] SB TARGET)]. Please fix the metadata consistency warnings. (HY000)
SQL Issued: SELECT TARGET.FILE_LOAD_DATE saw_0, TARGET.TARGET_FILECOUNT saw_1, TARGET.TARGET_FILECOUNT saw_2 FROM AUDIT_PROD ORDER BY saw_0.
Please tell me to achive my report.
Regards
Edited by: user8767586 on Jan 12, 2010 5:21 AM
Edited by: user8767586 on Jan 12, 2010 5:21 AM
Edited by: user8767586 on Jan 12, 2010 5:24 AM -
Changing display of item in column based on its value
Hi,
I'm confused as to how I can change the display attributes of an item in a column based on that items value. I've grepped through the forums and it seems there are ways to do this in the report query but that seems inefficient. My preferred method would be at the column level, I could set up some logic that says "if the value is X then display A and if the value is Y then display B". In this case A and B could be a snippet of HTML to display an image that represents the value.
Seems reasonable that this app would have this functionality and I'm sure it's there, I just can't seem to find it.
Help! Suggestions welcome, heckling encouraged!
Thanks,
JonJon,
You should probably start storing the images in a custom table as described here:
http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm
The following column is taken from the Products query in the sample application (page 3):
decode(nvl(dbms_lob.getlength(p.product_image),0),0,null,'<img src="'||apex_util.get_blob_file_src('P6_PRODUCT_IMAGE',p.product_id)||'" height="75" width="75" />') img
Note, getting this configured is a little tricky the first time. Notice that there is an item from page 6 referenced. Page 6 contains that item and a DML process both of which are needed for everything to work. Read more here:
http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/advnc.htm#BCGGJHEF
Regards,
Dan
http://danielmcghan.us
http://sourceforge.net/projects/tapigen -
To find a column based on a value
Hello Experts,
I have an urgent requirement. Based on a value in a particular column in a table, i have to select the previous column value.
I have tried using select statement with more compliaction which will affect the performance. Is there any user friendly logic to implement this.
Thanks in Advance!!
Moderator Message: Duplicate post, thread locked.
Edited by: Suhas Saha on Mar 5, 2012 3:01 PMI didnt get u...
plz post with code and proper information... -
Bex query that returns variable number of columns based upon variable value
I have a request to create a query that, at excution time, has a variable for 'nbr of months', and based on the value entered by the user, returns data for only the specified number of months. Value that can be entered can vary from 1 to 12. A simple example is, if the user enters 1, then they would only want to see one column, and if they entered 6, then they'd like to see 6 columns in the workbook. All suggestions on how to implement this dynamic columns on a workbook will be appreciated.
Thanks.
BNHi,
Do this->
1) first create a New Structure in Rows-> Place your New Selection and drag your KF.
2) Nw Create a New Formual under this structure. Now Create a Formula variable ( "ZFVXXX")with user-entry and ready for input and dimension as NUmber. and place in formula area. And hide this formula.
3)Now Create a New Customer-Exit variable on 0CALMONTH name as "ZCECMON" with following atrribute->Mandatory, Range(Interval) and remove check for Ready for entry.
4)Drag your 0CALMONTH in Rows above That Structure and restrict it to "ZCECMON".
5) Now go to CMOD and write this code.
INCLUDE ZXRSRU01 *
DATA: L_S_RANGE TYPE RSR_S_RANGESID. 'In global area
DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT. 'In global area
DATA: zmonth like /bi0/0calmonth.
CASE I_VNAM.
WHEN 'ZCECMON'.
IF i_step = 2.
LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
WHERE VNAM = 'ZFVXXX'.
zyear = sy-datum(4).
zmonth = sy-datum+4(2).
l_s_range-low = zmonth.
zmonth = zmonth + loc_var_range-low.
l_s_range-HIgh = zmonth.
l_s_range-sign = 'I'.
l_s_range-opt = 'BT'.
APPEND l_s_range TO e_t_range.
ENDIF.
ENDCASE.
6) activate the porject and go to rsrt and run there first.
Regards,
San!
Message was edited by: San! -
SQL Help Needed: Split & Replace - Update Column Vale
Hello experts,
I would like to seek for your expertise on how to update part of the column's value for many rows.
Let say, I have a table (table1) with 2 columns (col1 & col2)
col1 col2
100 abc.123
200 abc.456
300 abc.789
and i need to update abc to efg for col2 to become like
col1 col2
100 efg.123
200 efg.456
300 efg.789
any clue on how should the query looks like ?
pls advise, many thanks.For your given example, Michael's solution will work, however it may have problems if you had abc more than one time in a row.
For example, could you have a value like abc.123.abc in a row? If so, would you want to update it to efg.123.efg or to efg.123.abc?
If you want the firs, then Michael's is correct, if you want the second, then you would need something more like:
UPDATE table1
SET col2 = 'abc'||SUBSTR(col2, 4)
WHERE SUBSTR(col2, 1, 3) = 'abc'John -
Update column based on two columns
Hi,
MinValue MaxValue Desc
-1 -1
-1 1
-1 2
0 0
0 1
0 2
The above is my table which is having three columns MinValue, MaxValue, Desc. First two columns have data and I need to update the 3rd column 'Desc' based on two columns data.
I need to update like,
when MinValue=-1 and MaxValue=-1 then 'NotSpecified'
when MinValue=-1 and MaxValue=1 then 'Up to 1'
when MinValue=-1 and MaxValue=2 then 'Upto 2'
when MinValue=0 and MaxValue=1 then 'At lest 1'
when MinValue=0 and MaxValue=2 then 'At least 2'
when MinValue=0 and MaxValue=3 then 'At least 3'
The data in 'MaxValue' is like 1,2,3,4,5...50. So for each description it should append this value as mentioned above(till 'Up to 50', 'At least 50'). How can I do this with case statement?
Thanks,
Gangadhardeclare @T table ( MinValue int,MaxValue int, [Desc] nvarchar(100) );
insert @T ( MinValue, MaxValue )
values ( -1, 1 ) , ( -1, 1 ) , ( -1, 2), ( 0, 0), ( 0, 1), ( 0, 2)
select *
from @T
update @T
set [Desc] = case
when MinValue=-1 and MaxValue=-1 then 'NotSpecified'
when MinValue=-1 and MaxValue=1 then 'Up to 1'
when MinValue=-1 and MaxValue=2 then 'Upto 2'
when MinValue=0 and MaxValue=1 then 'At lest 1'
when MinValue=0 and MaxValue=2 then 'At least 2'
when MinValue=0 and MaxValue=3 then 'At least 3'
end
select *
from @T
T-SQL Articles
T-SQL e-book by TechNet Wiki Community
T-SQL blog
Maybe you are looking for
-
Is the imessage server down? because is not working in my ipod and my friend's one
because is not working in my ipod and my friend's one, then i logoff but now it doesnt let me log in :/
-
Screen saver won't go on, laptop won't sleep!
I've got a 17" laptop running 10.3.9. Everything used to be fine. Recently (after the latest Apple update? I'm not sure) I found that the laptop won't go to sleep. It's plugged in on my desk, and I've got the Energy Saver preference panel (set to "po
-
Hi, I have a project and I need to know if I should do it using Flash Builder and Flex or just using Flash and ActionScript (I Know Nothing About Flash Builder And Flex) The project is: Mp3 Player - Streaming Mp3's - Ads inside each song - XML driven
-
Hi, I m using Oracle 8i and EXP/IMP command to Export/Import all my data. Daily, I have to import my data in other computer, it takes many hours, as I have to delete all data first, then import all the data again. I want to insert only new/updated da
-
AEGP_RenderQueueState_RENDERING flag doesn't work in AE CC
Hi all.Can someone from Adobe engineers (Zac Lam??) explain why the following : AEGP_SuiteHandler suites(in_data->pica_basicP); AEGP_RenderQueueState rqState; suites.RenderQueueSuite1()->AEGP_GetRenderQueueState(&rqState); if(rqState ==