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,
Gangadhar
declare @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
Similar Messages
-
Sorting based on two columns in report
Hi,
we have one issue on sorting based on two columns in report.
In the report we are doing sorting on two columns(week_id and stage_name). I have attached the screen shot for the same. The sorting is first done on the week_id and then on the stage_name. The issue comes when we have no data for the stage 1 - Prospect in W1. The stage goes to the second position.
Please suggest if there is any work around to show the 1 - Prospect stage in W1.
Regards,
Ambika Nanda.what is w1? where is screenshot? and is stage seoncd sort? if so what is the issue?
-
JTable - One Column Heading for Two Columns
Can you adjust the default JTable to have one column heading for two columns of data? Is there a simple span command? I've looked at the api for JTable and JTableHeader and didn't see anything, is there something I'm missing? Any help would be appreciated.
What i am trying to accomplish is have column 'E' span 2 columns.
This is my code thus far, however it give the error from my pryor message. I am pretty sure it is because I'm using and Object[][] and a String[] instead of Vectors. What corrections do I need to make in order for my goal of:
[ A ][ B ][ C ][ D ][ E ][ F ][ G ]
[ 1 ][ 2 ][ 3 ][ 4 ][5][6][ 7 ][ 8 ]
Object[][] data = new Object[ROWS][COLUMNS];
String[] columnNames = {"A","B","C","D","E","E","F","G"};
table = new JTable(data, columnNames);
table.setBackground(Color.white);
table.addKeyListener(this);
DefaultTableCellRenderer d = new DefaultTableCellRenderer();
d.setHorizontalAlignment(JLabel.CENTER);
table.setDefaultRenderer(table.getColumnClass(0),d);
for (int i = 0; i < table.getColumnCount(); i++){
TableColumn aColumn = header.getColumnModel().getColumn(i);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = new DefaultTableCellRenderer(){
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
aColumn.setHeaderRenderer(renderer); -
Update multiple rows based on two columns in same row
I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?this?
update table tab_name
set date_time =date||time
where your_condition -
BC4J Objects with PKs based on two columns using multiple sequences
I have implemented a BC4J object that is based on a DB table that has two columns as the primary key. For example Table A's primary key is Group and ID and there is a DB sequence for each Group.
I use the BC4J object using servlets and JSPs and I have been able to implement an Update form.
I now want to implement a Create (New) form. I've read forum postings and info on the help regarding using the SequenceImpl class to override the EntityImpl object's create method as shown below:
protected void create(AttributeList attributeList)
super.create(attributeList);
SequenceImpl mySeq = new SequenceImpl("MY_SEQ",getDBTransaction());
setMyObjectId(mySeq.getSequenceNumber());
But as you can see I need to know the value of the group attribute before I can get the next value sequence:
For new EO belonging in Group1 I need sequence from "GROUP1_SEQ", Group 2 from "GROUP2_SEQ", etc.
I would like to put this code in the Entity Object where it belongs. I guess my problem is simply how to create a new row in the View Object with a passed parameter which is the value of Group.
Thanks in advance!Angelo:
How is the EO suppose to receive the group id? Is it from the view row? If so, the VO can pass that group id to the EO through the attribute list and calling the
public Row createAndInitRow(AttributeList nvp);
API.
Example code would be:
ViewObject myVO;
// myVO is initialized
AttributeList nvp = new oracle.jbo.NameValuePairs();
// GroupID is the attr name of the Group ID
nvp.setAttribute("GroupID", <some-value>);
Row row = myVO.createAndInitRow(nvp);
If you do that the create(AttributeList attributeList) method of the EO will receive the GroupID value coming from the VO.
Then, you can use that for your sequence.
Thanks.
Sung -
Parent-Child hierarchy based on two-column key
Hello
Is it possible to create a parent-child hierarchy, if the primary key of the table consists of two columns?
My table looks like:
TRACE_ID | DIAG_ID | SUPER_DIAG_ID
with TRACE_ID and DIAG_ID as PK.
If I define only DIAG_ID as PK, I can add a logical dimension (PC-hierarchy) without problems.
However when I also add TRACE_ID to my PK, I cannot select a member key in the new logical dimension window and therefore not create a logical dimension.
Is this a limitation of OBIEE and I have to merge the two colums (which would be rather bad, as there are FK relations to DIAG_ID) or is there a solution?
Regards
MatthiasDear Gowtham ,
I am very well aware of the level based hierarchy available in BO .
The issue that i have raised is all about the Parent Child Hierarchy which creates the recursive query.
I.e Every Parent has a child and that child can be parent of some other . (See the original example for more illustration) -
Qualified list item based on two columns
- fact table inludes following columns
key1
key2
measure1
In segment designer, update counts:
the query must counts two columns "key1 and key2" that key1 and key2 together must be distinct.Here you go:
SQL> WITH bill AS
2 (
3 SELECT 1000 AS billno, 101 AS advertiserid, 102 AS agencyid, 5000 AS total_value FROM DUAL UNION ALL
4 SELECT 1001, 101, 103, 5000 FROM DUAL UNION ALL
5 SELECT 1002, 101, 102, 1000 FROM DUAL
6 ), account AS
7 (
8 SELECT 101 AS account1_id, 102 AS account2_id, 'John' AS name, 50 AS empid FROM DUAL UNION ALL
9 SELECT 101, 103, 'James', 40 FROM DUAL UNION ALL
10 SELECT 101, 105, 'Joe', 60 FROM DUAL
11 )
12 /* End Sample Data */
13 SELECT a.name
14 , a.empid
15 , a.account1_id
16 , a.account2_id
17 , SUM(b.total_value)
18 FROM account a
19 JOIN bill b ON a.account1_id = b.advertiserid
20 AND a.account2_id = b.agencyid
21 GROUP BY a.name
22 , a.empid
23 , a.account1_id
24 , a.account2_id
25 ;
NAME EMPID ACCOUNT1_ID ACCOUNT2_ID SUM(B.TOTAL_VALUE)
John 50 101 102 6000
James 40 101 103 5000 -
Unique row based on two columns and single column
Dear Members,
I have a table which contains duplicate rows, for which a query should be able to fetch the unique row from the table. Here the unique is not based on one column, but it should be on two columns and also check for uniqueness on one column.
create table addr ( firstname varchar2(10), lastname varchar2(10), area varchar2(3));
insert into addr values('bob', 'james', '1');
insert into addr values('bob', 'james', '1');
insert into addr values('harry', 'bert', '1');
insert into addr values('jimmy', 'bert', '1');
insert into addr values('sam', 'mac', '1');
insert into addr values('sam', 'knight', '1');
insert into addr values('tom', 'sand', '1');
insert into addr values('cat', 'mud', '1');
The output of query should contain 3 rows.
bob - james
harry - bert or jimmy - bert [ either one of them, but not both ]
sam - mac or sam - knight [ either one of them, but not both ]
tom - sand
cat - mud
SELECT firstname, lastname as total from addr WHERE area = '1' GROUP by firstname,lastname; This does not take of single column duplication..
Any suggestions..SQL> with t_data
as
select 'bob' as firstname, 'james' as lastname, '1' as area from dual union all
select 'bob', 'james', '1' from dual union all
select 'harry', 'bert', '1' from dual union all
select 'jimmy', 'bert', '1' from dual union all
select 'sam', 'mac', '1' from dual union all
select 'sam', 'knight', '1' from dual union all
select 'tom', 'sand', '1' from dual union all
select 'cat', 'mud', '1' from dual
SELECT
firstname,
lastname,
area
FROM
SELECT
t.*,
row_number() over(partition BY firstname order by 1) rn,
row_number() over(partition BY lastname order by 1) rn1
FROM
t_data t
WHERE
rn = 1
AND rn1 =1 ;
FIRSTNAME LASTNAME AREA
bob james 1
cat mud 1
jimmy bert 1
sam knight 1
tom sand 1
SQL> -
Compare two tables based on two columns
Hi,
my tables looks like this:
Desc Table A (account)
Account1_id
Account2_id
name,
empid
Table B (Bill )
BillNo
Advertiserid
agencyid
total vvalue
I need to pick up total value from table B where the unique combination of advertiser-Agency id is the same as the given account1_id -Account2_id combination in table A for each employee id.
In other words my output should be like
Empid | Account_id (should be same as advertiserid)| Account2_id (same as agencyid) | sum(total_value) for this adv-agency combination.....
objective: Get the total value from table B for each unique account1-account2 combination (advertiser-agency in other words) .
I am not sure if I should use a coreelated subquery or how to handle the situation....Right now I am just checking the two columns separately like this:
select.......from a,b
where b.advertiser_id = a.account1_id and b.agencyid = b.account2id
Is it correct to do so? I have a feeling that I am missing something if I join them seperately like this......Any advice on this?
I am using Oracle 10g. Hope I am clear.Please let me know. Thankx in advance.Here you go:
SQL> WITH bill AS
2 (
3 SELECT 1000 AS billno, 101 AS advertiserid, 102 AS agencyid, 5000 AS total_value FROM DUAL UNION ALL
4 SELECT 1001, 101, 103, 5000 FROM DUAL UNION ALL
5 SELECT 1002, 101, 102, 1000 FROM DUAL
6 ), account AS
7 (
8 SELECT 101 AS account1_id, 102 AS account2_id, 'John' AS name, 50 AS empid FROM DUAL UNION ALL
9 SELECT 101, 103, 'James', 40 FROM DUAL UNION ALL
10 SELECT 101, 105, 'Joe', 60 FROM DUAL
11 )
12 /* End Sample Data */
13 SELECT a.name
14 , a.empid
15 , a.account1_id
16 , a.account2_id
17 , SUM(b.total_value)
18 FROM account a
19 JOIN bill b ON a.account1_id = b.advertiserid
20 AND a.account2_id = b.agencyid
21 GROUP BY a.name
22 , a.empid
23 , a.account1_id
24 , a.account2_id
25 ;
NAME EMPID ACCOUNT1_ID ACCOUNT2_ID SUM(B.TOTAL_VALUE)
John 50 101 102 6000
James 40 101 103 5000 -
How to insert into date column based on other columns?
Hi
I have four columns in a table called game named as
R_Day - Type - Number
R_Month - Type - Number
R_Year - Type - Number
R_Date - Type - Date
I have around 1000 records and i want to fill R_Date column based on the data in the R_Day,R_Month,R_Year.
How to write a query to fill the R_Date column based on other three columns.
Thanks
srinivasselect
to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
dt from (select 23 R_Day,07 R_Month,2007 R_Year from
dual);
Hi,
Update <Table Name> set R_Date=select
to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
from <Table Name>
Regds.
Nirmal
SQL> select * from test;
R_DAY R_MONTH R_YEAR R_DATE
1 1 2007
21 11 2007
SQL> update test
2 set r_date = select to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
3 from test;
set r_date = select to_date(R_Day||'-'||R_Month||'-'||R_Year,'DD-MM-YYYY')
ERROR at line 2:
ORA-00936: missing expression
SQL> update test
2 set r_date = to_date(r_day||'-'||r_month||'-'||r_year,'dd-mm-yyyy');
2 rows updated.
SQL> select * from test;
R_DAY R_MONTH R_YEAR R_DATE
1 1 2007 01-JAN-07
21 11 2007 21-NOV-07
NB:Please test before posting.. -
How to create new calculated column based on filtered columns?
Dear All,
I'm using Oracle Analysis.
I have two column, each one have different formula.
My Formula based on filter.
Column1
FILTER("DW"."SUM_PLAN_MONTH_AMOUNT" USING ("DW"."PLAN_YEAR" BETWEEN YEAR(DATE'@{P_BEGIN_DATE}') and YEAR(DATE'@{P_END_DATE}')))Column2
FILTER("PAYMENTS"."SUM_PAY_AMOUNT" / 1000 USING ("PAYMENTS"."PAY_DATE_PAID" BETWEEN DATE'@{P_BEGIN_DATE}' AND DATE'@{P_END_DATE}'))How to add new calculated column based on those two column?
For example:
Column1 | Column2 | NewColumn
5 | 10 | 10 / 5 * 100
7 | 12 | 12 / 7 * 100
Regards,
Eba
Edited by: Erdenebayar on Apr 19, 2012 1:42 PM
Edited by: Erdenebayar on Apr 19, 2012 3:37 PMHello MK,
I have a tried following formula. It is working, but result is not filtered.
I filtered "PAYMENTS"."SUM_PAY_AMOUNT" and "DW"."SUM_PLAN_MONTH_AMOUNT" columns.
"PAYMENTS"."SUM_PAY_AMOUNT" / "DW"."SUM_PLAN_MONTH_AMOUNT" * 100Can you share me some tutorial?
BR,
Eba
Edited by: Erdenebayar on Apr 19, 2012 3:43 PM
Edited by: Erdenebayar on Apr 19, 2012 3:43 PM
Edited by: Erdenebayar on Apr 19, 2012 3:43 PM -
Select column 1 into two column from same table
Dear Sir
I have a data like
studid makr tottal credit total average mark semester
251; 249.84; 41; 6.09; 1
106; 285.32; 42; 6.79; 1
285; 263.88; 38; 6.94; 1
251; 202.40; 28; 7.23; 2
106; 293.20; 39; 7.52; 2
285; 228.14; 39; 5.85; 2
I want to select average mark semester1 and semester 2 in different column
studid average_mark_ semester1 average_ mark_ semester_ 2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
please help me
regards
sanat kumar
thanks in advanceDear Sir,
Thank u for your prompt answer.
But I want to select student id and average mark based on semester
out put supposed to be
student id average_makr_sem1 average_mark_sem2
251 6.09 7.23
106 6.79 7.52
285 6.94 5.85
I want to select the average mark in different column based on semester
Please look into
thanks
regards
sanat -
Split one column value into two columns using t-sql
Hi All,
I have one varchar column in a table.
Col1
ABC-12C4
BC-A345
CD
XYZ
How to split this into two columns like this using t-sql
Col1 Col2
ABC 12C4
BC A345
CD
XYZ
Thanks,
RH
sqlassuming a static delimiter, and the split will end up with a max of 2 columns, something like this would work. basically you just need to determine where the delimiter is, and then use the left and right functions to find the 2 pieces.
declare @t table(value varchar(10))
insert into @t(value)
values
('ABC-12C4'), ('BC-A345'), ('CD'), ('XYZ')
select
case
when charindex('-', value) != 0 then left(value, charindex('-', value) - 1)
else value
end as col1,
case
when charindex('-', value) != 0 then right(value, len(value) - charindex('-', value))
else ''
end as col2
from @t -
SharePoint 2013 Make Calculated Column based on Custom Column
In SharePoint 2013, I am trying to create a Calculated Column that is a shortened display of another Custom Column. The Calculated Column would just show the first 100 characters concatenated with "..." like in the following formula:
=LEFT([CustomColumn],100)&"..."
However, every time that I go to create this calculated column, SharePoint doesn't provide my [CustomColumn] in the "Insert Column:" list. If I type it in anyway, SharePoint throws an error.
Details on my Column, List, and Site below:
Col. Type: Multiple lines of text
Col. Group: Custom Columns
Col. Text Type: Enhanced rich text
List Content Type: Custom Type Inherits from Event
Site Type: Publishing
Also, to no avail, I found this similar post (link below), but creating the Site Column and Calculated Column
before adding it to the Content Type did not work for me.
http://social.technet.microsoft.com/Forums/sharepoint/en-US/26a7517e-ba43-4c49-95aa-3e6f7f4207ba/calculated-field-in-content-type-not-working
Anyone out there know how to coax SharePoint into submission?!Multi lines of text are one of the types of columns which can't be used by calculated columns/fields. Among such unusable columns are also Lookup columns, People columns, External Columns, MMS columns, etc.
Scott Brickey
MCTS, MCPD, MCITP
www.sbrickey.com
Strategic Data Systems - for all your SharePoint needs -
How to split rows based on two columns..
Hi all...
I have a requirement.
I have product column, sell, purchace prices..(total of three columns) in a data set.
my data set is such a way that..if sale price exists...there is no purchase price and vice versa..
I need too present in a report ,two tables:
table 1 consists of only Sale price items
table 2 should contain only Pruchase Items.
Please see the below picture for clear understanding..
Is that doable? Where do we need to impose a condition?I tried to impose a condition but,it didnt seem to work
http://i51.tinypic.com/29xfdc6.jpg
Please help.Can you send me the template and xml file to [email protected]? I can try to help.
Did you try to filter out the records by the sale price or purchase price column not equal to null?
Thanks,
Bipuser
Maybe you are looking for
-
Iphone 4s sound fluctuating after upgraded to IOS 8.1.2
Hi, I recently have Iphone 4s from my sister and when I updated to IOS 8.1.2 the sounds is fluctuating. Most of the time, you will not hear the sound speaker while playing the music and playing games. Calling is fine only the speaker sound. When it
-
Relation b/w vendor and company code
hi, i m working on vendor details report, where i wanna select vendor on the comany code parameter. but i m not getting any relation b/w bukrs n lifnr so plz help me if u no anything regarding this. this is very urgent. thanks in advance marks wi
-
Full database export hangs (Oracle9i rel2)
I recently migrated successfully from oracle8i rel 8.0. to oracle9i release 2,But now am not able to do a full database export.has anyone experienced this and whats the remedy?. the text i get is listed below. Microsoft Windows [Version 5.2.3790] (C)
-
Migrating from Seagate Info 7.5 to CR Server XI release 2 - HTML problem
We are currently trying to migrate from using Seagate Info 7.5 to using Crystal Reports Server XI Release 2, for our reports generation / scheduling. We currently have a number of reports which are generated as HTML and saved to a network shared fold
-
Get table ID for drill down (javascript functions)
I want to implement some custom drill downs. When you click on a column to drill down, it uses the following javascript function: RTDr(saw_5_6,0,0) where in this case, "saw_5_6" is my current table. Since this is dynamically set and the table name ca