Selecting from a column based on the id
Hello All,
Is there a way to update a table based on the column id?
Example: I have a table where column 2 is an accumulated dollar amount. Each row of the column is a lease.
I need to update column 3 with $$ that i get from my cursor say x. Then column 4 is needs to be updated with
amount in column 2+ amount in column3.
Again column 5 needs to be update with the next $$amount that i get from my cursor x. Now column 6 needs to
be updated with amount in value in column 4 and column5...so on and so forth.
I can get the column names from the dba_tab_columns. However I don't know if those column names can be used in the
update/insert statements to populate the table.
Thanks,
Chiru
Hi,
I'm not sure I understand the problem.
You can use column names in a INSERT and UPDATE statements. for example:
UPDATE my_table
SET column_3 = x
, column_4 = column_2 + column_3;When you use a column name to the right of the "=" sign, it always refers to the old value.
In the 3rd line of the example above, column_4 is set to the old value of column_2 plus the old value of column_3, not the new value (x) that was given to column_3 in the 2nd line.
If you have a problem, post
(1) a little sample data (three ros, maybe) before UPDATE, and
(2) what those same rows should be after the UPDATE,
(3) explanation, (such as "I want to add the parameter :amt to column_5 and subtract :amt from column_6.")
Similar Messages
-
Returning a result from multiple columns based on the last date that the column has a value.
I have this table named (pmtable)
ctrlno jobid docdate work1 work2 work3
1 7 2/12/2014 20 hrs
10 hrs
2 7 2/22/2014 35 hrs
15 hrs
3 7 2/28/2014
12 hrs
4 8 1/17/2014 15 hrs
13hrs
I want the result to be like this
jobid work1 work2 work3
7 35hrs 10 hrs 12 hrs
Is this possible?Hi serenace,
To achieve your requirement, you can reference the below.
DECLARE @Tbl TABLE(ctrlno INT,jobid INT,docdate DATE,work1 INT,work2 INT,work3 INT);
INSERT INTO @Tbl VALUES(1,7,'2/12/2014',20,10,NULL);
INSERT INTO @Tbl VALUES(2,7,'2/22/2014',35,NULL,15);
INSERT INTO @Tbl VALUES(3,7,'2/28/2014',NULL,NULL,12);
INSERT INTO @Tbl VALUES(4,8,'1/17/2014',15,13,23);
INSERT INTO @Tbl VALUES(4,8,'2/17/2014',15,NULL,NULL);
INSERT INTO @Tbl VALUES(4,8,'3/17/2014',NULL,16,NULL);
;WITH cte AS(
SELECT jobid,docdate,attr,value FROM
@Tbl
UNPIVOT
(value FOR attr IN(work1,work2,work3)) AS UT
cte2 AS(
SELECT jobid,attr,value , ROW_NUMBER() OVER(PARTITION BY jobid,attr ORDER BY docdate DESC) AS rn
from cte
SELECT jobid,ISNULL([work1],0) [work1],ISNULL([work2],0) [work2],ISNULL([work3],0) [work3] FROM
cte2
PIVOT
(SUM(value) FOR attr IN([work1],[work2],[work3])) AS PT
WHERE rn=1
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
Restrict selection from LDB 'DDF' based on FI Doc number(BELNR)?
Hi all,
I am trying to restrict selection from LDB 'DDF' based on FI Doc number(BELNR).
Even if i pass only one document number in selection-screen, the program is still printing lot of documents?
Where I am going wrong?
*& Report ZSUB_READ_LDB
REPORT ZSUB_READ_LDB.
DATA wa_BSEG TYPE BSEG.
SELECT-OPTIONS s_BELNR FOR wa_BSEG-BELNR.
DATA: callback TYPE TABLE OF ldbcb,
callback_wa LIKE LINE OF callback.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.
callback_wa-ldbnode = 'BSEG'.
callback_wa-get = 'X'.
callback_wa-get_late = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_BSEG'.
APPEND callback_wa TO callback.
CLEAR callback_wa.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BELNR'.
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BELNR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname = 'DDF'
variant = ' '
TABLES
callback = callback
selections = seltab
EXCEPTIONS
ldb_not_reentrant = 1
ldb_incorrect = 2
ldb_already_running = 3
ldb_error = 4
ldb_selections_error = 5
ldb_selections_not_accepted = 6
variant_not_existent = 7
variant_obsolete = 8
variant_error = 9
free_selections_error = 10
callback_no_event = 11
callback_node_duplicate = 12
OTHERS = 13.
IF sy-subrc ne 0.
WRITE: 'Exception with SY-SUBRC', sy-subrc.
ENDIF.
*& Form CALLBACK_BSEG
text
-->NAME text
-->WA text
-->EVT text
-->CHECK text
FORM CALLBACK_BSEG USING name TYPE ldbn-ldbnode
wa TYPE BSEG
evt TYPE c
check TYPE c.
CASE evt.
WHEN 'G'.
WRITE: / wa-BELNR.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM. "CALLBACK_BSEGHi Andreas,
I have included bukrs and gjahr too...but if I input only one invoice number the report is printing a lot of invoices.
Not sure from where the data is being picked up?
Sorry of poor formatting of code.
Thanks ,
Subba
*& Report ZSUB_READ_LDB
REPORT ZSUB_READ_LDB.
TYPE-POOLS: RSDS, RSFS.
DATA wa_BSEG TYPE BSEG.
SELECT-OPTIONS s_BELNR FOR wa_BSEG-BELNR.
SELECT-OPTIONS s_BUKRS FOR wa_BSEG-BELNR.
SELECT-OPTIONS s_GJAHR FOR wa_BSEG-BELNR.
DATA: callback TYPE TABLE OF ldbcb,
callback_wa LIKE LINE OF callback.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.
DATA: TEXPR TYPE RSDS_TEXPR,
FSEL TYPE RSFS_FIELDS.
start-of-selection.
callback_wa-ldbnode = 'BSEG'.
callback_wa-get = 'X'.
callback_wa-get_late = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_BSEG'.
APPEND callback_wa TO callback.
CLEAR callback_wa.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BELNR'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BELNR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BUKRS'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BUKRS TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'GJAHR'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_GJAHR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname = 'DDF'
variant = ' '
EXPRESSIONS = TEXPR
FIELD_SELECTION = FSEL
TABLES
callback = callback
selections = seltab
EXCEPTIONS
ldb_not_reentrant = 1
ldb_incorrect = 2
ldb_already_running = 3
ldb_error = 4
ldb_selections_error = 5
ldb_selections_not_accepted = 6
variant_not_existent = 7
variant_obsolete = 8
variant_error = 9
free_selections_error = 10
callback_no_event = 11
callback_node_duplicate = 12
OTHERS = 13.
IF sy-subrc ne 0.
WRITE: 'Exception with SY-SUBRC', sy-subrc.
ENDIF.
*& Form CALLBACK_BSEG
text
-->NAME text
-->WA text
-->EVT text
-->CHECK text
FORM CALLBACK_BSEG USING name TYPE ldbn-ldbnode
wa TYPE BSEG
evt TYPE c
check TYPE c.
CASE evt.
WHEN 'G'.
WRITE: / wa-BELNR.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM. "CALLBACK_BSEG -
I want to retrieve data from p0001-PLANS based on the below condition,
Hi,
I want to retrieve data from p0001-PLANS
based on the below condition
select stext from hrp1000 where plvar = '01' and otype = 'S' and objid = p0001-plans and begda GE pn-begda and endda LE pn-endda.
Thanks,
Rama.Hi
Based on the Query you have specified thoise are stoerdin an Internal table- then
select stext from hrp1000 into table t_hrp where plvar = '01' and otype = 'S' and objid = p0001-plans and begda GE pn-begda and endda LE pn-endda.
The check table for this PLANS is T528B .
if t_hrp[] is not intitial.
select * from t528B intot table t_528 where plans eq t_hrp-plans.
endif.
Now you can get the PLANS data.
Refer to the Text tbale for PLANS - T528T
To get the TEXTS -
if t_hrp[] is not initial.
select * from T528T into table t_528T where plans eq t_hrp-plans.
endif.
Regards
Lekha -
When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators. Excel allows you to do this during the import.. Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.
Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
(I don't have an iPad, so I don't know the iOS answer.) -
Need to show the images in calculated column based on the condition in sharepoint 2013.
Hi ,
I'm working in sharepoint 2013, In this i want to show an image in calculated column based on the condition, but image is not showing .
In sharepoint 2010 its working with help of javascript in content editor on the same page. Same thing i tried in SP 2013. but doesn't work.
Could any one please give proper solution for this?
Thanks in advance.
by,
Siva.Hi please provide the JS you have used in the content editor as well as the calculation for the column so we can better understand what's maybe differs?
Blog: chrisstahl.wordpress.com Twitter:
@Cstahl -
How can i dynamically select columns based on the input parameter?
I have an input parameter which takes single numeric value.
Based on this value i have to dynamically select table-columns .
For eg: if i have following fields in my table :
SEM_1
SEM_2
SEM_3 and SEM_4.
And if i give numeric input as 2 , then i have to select "SEM_2" column only.
if the input is 3 then i have to select "SEM_3" only and leave the rest of the columns.
how do i achieve this dynamic feature in the "Select ..... From...... table...." statement in the ABAP??Hi,
you should try something like this.
TYPES: cond(72) TYPE c.
data: condtab TYPE TABLE OF cond,
condw type cond.
data: lv_field(30) type c value 'SEM_'.
write p_num to lv_field+4(1).
condw = lv_field.
append condw to condtab.
SELECT (CONDTAB) FROM table INTO.....
Kostas
Message was edited by:
Kostas Tsioubris -
How can I select and delete rows based on the value in one column?
I searched through the discussion board, and found a thread on deleting blank rows, but not sure how to modify it to work with my issue.
I have put together a rather complicated spreadsheet for designing control systems, it calculates parts needed based on check boxes selected in a second spreadsheet.
Since not all systems require all parts there are many rows that have a 0 quantity value, I would like to select these rows and delete them once I have gone through the design phase (checking off required features on a separate sheet).
I like the way the other thread I found will gather all the blank rows at the bottom without changing the order of the rows with data in them.
I don't understand exactly how the formula in the other thread works well enough to modify it to look for a certain column.
I hope I made myself clear enough here, to recap, I would like to sort the rows based on a zero value in one (quantity) column, move them (the zero quantity rows) to the bottom of the sheet, and then delete the rows with a zero quantity (I can delete them manually, but would like to automate the sorting part).
Thanks for any help anyone can provide here.
DannyI apologize but, as far as I know, Numbers wasn't designed by Ian Flemming.
There is no "this column will be auto-destructing after two minutes"
You will have to use your fingers to delete it.
I wish to add a last comment :
if your boss has the bad habit to look over your shoulder, it's time to find an other one.
As I am really pig headed, it's what I did. I became my own boss so nobody looked over my shoulder.
Yvan KOENIG (VALLAURIS, France) mercredi 13 juillet 2011 20:30:25
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
Please : Search for questions similar to your own before submitting them to the community
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer ! -
How to exit from SQL*Plus based on the return value of a SQL select stment?
Hi
I have a SQL script executed from SQL*Plus. I would like to know if SQL*Plus
supports any kind of branching or exiting from script execution based on a
returned value of a SQL select statement. I am on 9i.
Regards,
Tamas Szecsyin sqlplus, you have whenever
ex:
whenever sqlerror exit failure
insert into ...
-- if this fails, then you will be out
insert into ...
-- if this fails, then you will be out
whenever sqlerror continue
insert into ...
-- if this fails, this continues
insert into ...and you have PL/SQL
declare x number;
begin
select count(*) into x from emp;
if (x=14) then null; end if;
end;
/note that you can mix those in some case
-- exit if there is no row in emp
whenever sqlerror exit 1
var dummy number
exec select count(*) into :dummy from emp having count(*)!=0 -
Select from different tables based on value
Hi Forum,
I'm stuggling with a problem:
In a table, I have two columns, pref_type and pref_value. Column pref_type stores a number value that is linked to a preference type, whereas column pref_value stores the value of that preference.
Unfortunately, the data model is such that per preference type a different tables needs to be used, so for example, if
pref_type = 1, table to query is A, whereas if
pref_type = 2, table to query is B.
I now want to write a query that resolves the preferences, ie it should branch to the respective table based on pref_type and search for pref_value and deliver back a different column of that respective table.
My first approach was like that:
select decode (pref_value, 1, (select result from A where pref_value = ???),
2, (select result from B where pref_value = ???)
where the three ??? depict the problem I'm having, as Oracle doesn't allow me to have a harmonized subquery here.
How do I achieve this?
Thanks for any help,
J. SiebenI believe this is what you are trying to get at:
SELECT DECODE(m.pref_type, 1, (SELECT result FROM a
WHERE a.pref_value = m.pref_value),
2, (SELECT result FROM b
WHERE b.pref_value = m.pref_value)
FROM my_table mAlthough, if the tables are large, that might be pretty slow. Better than an outer join, but one of those correlated queries is going to be run for each row in my_table. You could lso try something like:
SELECT m.pref_type, r.result
FROM my_table m,
(SELECT 'A' tbl, pref_value, result
FROM a
UNION ALL
SELECT 'B', pref_value, result
FROM b) r
WHERE DECODE(m.pref_type, 1, 'A', 'B') = r.tbl and
m.pref_value = r.pref_valueHTH
John -
Inserting new columns based on the condition!
Hi guys,
I have a very simple query like the following…
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1
FROM database_001.table2 table1 LFET OUTER JOIN database_001.table2 table1 on (table2.column_code1 = table1.column_code1)
From this query, its returning me a result set of something like below:
column_code1 column_description1 column_code2 column_description2
RO1 BOOK RL1
PDF/ECOPY
RO2 PAPER RL2
CONFERENCE
RO5 JOURNAL
RL11 OTHER
Now, on the above query I want to insert three extra columns with the name (status, location and contact) where the results in the extra three columns would be based on the conditions I want to define in the query based on the above results…
Something for example (sorry, I am not trying to write a condition: my question is how to write it),
if column_code1 = RO1 and column_description2 = PDF/ECOPY on status column it should return a value ‘ONLINE’ & on location column it should return ‘WEB’ and on contact column it should write ‘BOB’.
Also,
if column_code1 = RO5 and column_description1 = JOURNAL on status column it should return a value ‘ON PRESS FOR PRINT’ & on location column it should return ‘S.R STREET, LONDON’ and on contact column it should write
‘SMITH’ like below result…so the final output should be the top four columns and the extra three columns…I hope someone can help me into this…thanks a lot…
status location
contact
ONLINE WEB
BOB
ON PRESS FOR PRINT S.R STREET, LONDON SMITHHi artistdigital,
you can use case statment for same in sql server. MSDN link - > http://technet.microsoft.com/en-us/library/ms181765.aspx
Try code like this:
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1,
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'ONLINE'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'ON PRESS FOR PRINT'
end as [status],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'WEB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'S.R STREET, LONDON'
end as [Location],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'BOB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'SMITH'
end as [contact]
FROM table2
join table1
on table2.column_code1 = table1.column_code1
Regards Harsh -
Sort a table with two columns based on the first
I have a powershell table with the columns 'Used Perc' and 'ID'.
This was formed from the following
$a = @{Expression={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)};Label="Used Perc";width=25}, @{Expression={$_.nStatisticalDiskIdentificationID};Label="ID";width=15}
$GLOBAL:CSV2 = Import-CSV $STATDISKOUT | Format-Table $a
Before this, the file $STATDISKOUT had the columns 'nUsed_Avg', 'nSize', and 'nStatisticalIdentificationID'.
My question is, how would I sort the new table based on 'Used Perc' but keeping the corresponding 'ID' column lined up to the right value?We use a select statement to reorder columns and recalculate, The formatters just go at the end to adjust the display.
Import-Csv <file> | select <column order format> | Format-Table
or you can do it in the table:
Import-Csv <file | Format-Table -Properties ,f1.,f2.,,f3....Here is how to inset a sort inline:
$a=@{
L='ID';
E={$_.nStatisticalDiskIdentificationID};
L='Used Perc';
E={[System.Math]::Round(($_.nUsed_Avg/$_.nSize)*100,1)}
Import-CSV $STATDISKOUT | Select $a | Sort 'Used Perc' | Format-Table -Auto
¯\_(ツ)_/¯ -
How do I select a date column and display the millesecond along with it.
I am trying to select a date column from database and want to
display millesecond with it. How do I do this. I am aware of
the "alter session set NLS_DATE_FORMAT = 'MM/DD/YY HH:MI:SS'"
command. However, I do not know how to display this with the
millesecond.
Thanks for all the help.Example:
SQL> CREATE OR REPLACE JAVA SOURCE
2 NAMED "MyTimestamp"
3 AS
4 import java.lang.String;
5 import java.sql.Timestamp;
6
7 public class MyTimestamp
8 {
9 public static String getTimestamp()
10 {
11 return (new
12 Timestamp(System.currentTimeMillis())).toString();
13 }
14 };
15 /
Java created.
SQL> CREATE OR REPLACE FUNCTION my_timestamp
2 RETURN VARCHAR2
3 AS LANGUAGE JAVA
4 NAME 'MyTimestamp.getTimestamp() return java.lang.String';
5 /
Function created.
SQL> CREATE TABLE test_time
2 (date_col VARCHAR2 (23))
3 /
Table created.
SQL> INSERT INTO test_time (date_col)
2 SELECT my_timestamp
3 FROM dual
4 /
1 row created.
SQL> SELECT date_col
2 FROM test_time
3 /
DATE_COL
2001-11-02 14:58:51.766 -
Calculated column based on the value of a prompt
Hi all
I created a page prompt for the user than he can choose the years period: for example Year: between 2009 and 2015
In the report I have one of the measures that and I only want to display for the year 2009.I don't want to sum from 2009 till 2015
currently It calculating the sum from 2009 till 2015 and I only want it for the begining year of the period that the user selects in the prompt
How can I do that??
Regardstry to de-attach the prompt from your SA i.e. once you choose a column month to be in the prompt edit the formula and enter e.g. 'Start month'; then select the same column again and edit the formula and enter e.g. 'End month'; for each of the columns set the operator to equal; add presentation variables for both columns; then in the report use these variables in the filter for the remaining measures and for the one in question use the filter using; see if this would work
-
i have table with tow column recid and xmlrecord (xmltype)
<row id="52843" xml:space="preserve">
<c1>Refund of Domestic Payment Order</c1>
<c2>Ref Dom Py Or</c2>
<c3>PLl</c3>
<c20>1</c20>
<c21>62_TAABSINPUTT___OFS_TAABS</c21>
<c22>0803181605</c22>
<c23>62_TAABSINPUTT_OFS_TAABS</c23>
<c24>SA0010001</c24>
<c25>1</c25>
</row>
i need to select from table where <c24> =SA0010001
please need helpIf you would have posted the XML path with nodes, I can provide the SQL with full path but try to use the below SQL changing their SQL path and root
select extractValue(object_value, '/<XMLPath>/C24')
as Id
from invoicexml_tbl;
If you want to use in WHERE clause, use existsnode method
select * from invoicexml_tbl
where existsNode(object_value, '/<XML Path>/row[c24="SA0010001"]') = 1;
Maybe you are looking for
-
To open you need a Java SE 6 runtime. Why, when I have 1.7 installed?
PREFACE: I've read most of the posts on here that discuss this issue but none have provided a real answer to this. I'm on Moutain Lion w/ all the latest updates from the App Store. I've installed Oracle's latest Java JDK (7u11) because of the recent
-
Well, the title is quite self-explanatory but I'd also like to add that: I noticed that conky reads correct values and after exactly 3 refreshes it just displays 0, no matter how long is the update interval. /sys/class/hwmon displays correct values,
-
Error message when trying to put whole cd on ipod
Everytime I try to put a whole cd on my ipod, i get an error message that states this song cannot be played on this ipod. If i put mp3's on the ipod, it works fine. Is there a certain setting I need to be on?
-
JComboBox as a cell editor in JTable
Hi, I've set one of my columns in my table to have a JComboBox as a cell editor. This is fine but my problem is that each row has different values in the JComboBox but when I update each row the column with the JComboBox they all end up with the same
-
Hi, We are migrating the siebel database from DB2 to Oracle 11g. While doing the migration, the following values are found for the siebel related tables on DB2. for example: CREATE TABLE S_SERVICE_SCRPT ( ROW_ID NVARCHAR2(15) NOT NULL, CREATED TIMEST