How to select only last 4 characters in a column of type varchar2
The data in column P_JACKS.LABEL is in the form of:
294-001,
B01-099,
194A-098,....
I'd like to select only the 3 characters following the '-' dash, and find the maximum of that set.
This must be simple, I know, but so am I. Can someone please help me with this?
Thanks!!
I'm sure there is some slick regexp way to do it but this should work
WITH t AS
(SELECT '294-001' value FROM dual
UNION ALL
SELECT 'B01-099' FROM dual
UNION ALL
SELECT '194A-098' FROM dual
SELECT greatest( (SUBSTR( value,LENGTH(value)-2,1)), (SUBSTR( value,LENGTH(value)-1,1)), (SUBSTR( value,LENGTH(value))) )
FROM tmaybe I misunderstood do want to the max for the whole group as in 99
or did you mean 3 rows with values
1
9
9
which is what I did
Edited by: pollywog on Sep 9, 2010 6:45 PM
Edited by: pollywog on Sep 9, 2010 6:47 PM
Similar Messages
-
Hi all!
How do I select only last date for each contragentid?
So for contragentid = 111270 it should be only '14.05.2010'.
select dd.contragentid,
decode(dd.ratingvalue,'PK1',1,'PK2',2,'PK3',2,'PSR',2,'UN4',2,'VVL',2,'BK',4,3) as ratingvalue from
(select 36 as contragentid, 'UN1' as ratingvalue, '25.02.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, '26.11.2009' as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, '14.05.2010' as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, '14.06.2011' as ratingstartdate from dual ) dd
where dd.ratingstartdate <= to_date('31.05.2010', 'DD.MM.YYYY')Also I need to select all rows from second test case for those contragentid which absent in first case, it should be one statement for both cases.
select * from
(select 5 as contragentid, 2 as ratingvalue from dual
union all
select 111270 as contragentid, 1 as ratingvalue from dual ) hhThanks ahead!I've got solution for the first part of my beginning post:
select dd.contragentid,
decode(dd.ratingvalue,'PK1',1,'PK2',2,'PK3',2,'PSR',2,'UN4',2,'VVL',2,'BK',4,3) as ratingvalue,
last_value(dd.ratingstartdate) over
(partition by dd.contragentid ORDER BY dd.contragentid, dd.ratingstartdate desc
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS last_ratingstartdate
FROM
(select 36 as contragentid, 'UN1' as ratingvalue, to_date('25.02.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, to_date('26.11.2009','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, to_date('14.05.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, to_date('14.06.2011','DD.MM.YYYY') as ratingstartdate from dual ) dd,
(select contragentid, max(ratingstartdate) as ratingstartdate from
(select 36 as contragentid, 'UN1' as ratingvalue, to_date('25.02.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK1' as ratingvalue, to_date('26.11.2009','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'PK3' as ratingvalue, to_date('14.05.2010','DD.MM.YYYY') as ratingstartdate from dual
union all
select 111270 as contragentid, 'BK' as ratingvalue, to_date('14.06.2011','DD.MM.YYYY') as ratingstartdate from dual )
where ratingstartdate <= to_date('31.05.2010', 'DD.MM.YYYY')
group by contragentid ) uu
where
uu.contragentid = dd.contragentid
and uu.ratingstartdate = dd.ratingstartdateNow I need to add contragentid from the second test case (see beginning post) which are absent in my first test case. -
Anyone know how to select only even or odd numbered files in lightroom?
Anyone know how to select only even or odd numbered files in lightroom? I need to reduce the quantity of images in my timelapse sequence and this would help me greatly since there are 8250 images and doing this maually would be tediuos and make me want to kill myself.... : )
Do this.
If they are jpegs, use .jpg instead of CR2
Be sure to save this as a preset, as you WILL need it again. Mine is named "select even CR2", that is why it says that in the upper right. -
Swapping the first and last characters in a column
Hi,
Fairly new to T-SQL and i want to swap the first and last characters in a column.
Thanks
Umar JavedLikewise i have also tried your suggestion and i still seem to be getting errors:
IF (@TYPE = 'SCRAMBLE')
BEGIN
DECLARE @SQLCOMMAND VARCHAR(2000)
SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE +
STUFF(STUFF(@VALUE,1,1,RIGHT(@VALUE,1)),LEN(@VALUE),1,LEFT(@VALUE,1))
EXECUTE(@SQLCOMMAND)
END
Umar Javed
Please post the errors.
EDIT: Actually looking at your code this will bring errors:
IF (@TYPE = 'SCRAMBLE')
BEGIN
DECLARE @SQLCOMMAND VARCHAR(2000)
SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE + ' = STUFF(STUFF('+@VALUE+',1,1,RIGHT('+@VALUE+',1)),LEN('+@VALUE+'),1,LEFT('+@VALUE+',1))'
PRINT @SQLCOMMAND
EXECUTE(@SQLCOMMAND)
END
I've also added a print command so it will show you what the code looks like upon concatenation. It's much easier to debug this way. -
How to select only first few values in a Column
Hi, in one of the column of type SDO_GEOMETRY. In that column we have many values. Example : *(-6.33787700000002, 56.547309, -6.33786800000001, 56.547279, -6.33781400000001, 56.547249, -6.33776900000001)*
I wanted to know how can i select only first two or last two values from within the column.
Eg: i want only -6.33787700000002, 56.547309 to be displayed
ThanksHi,
Are the value specified here are multirow or single row data?
if it is multi row, Karthick solution should work. Else if it is a single row then try this
with T as
select '-6.33787700000002, 56.547309, -6.33786800000001, 56.547279, -6.33781400000001, 56.547249, -6.33776900000001' SDO_GEOMETRY from dual
-- end of sample data
select substr(SDO_GEOMETRY,1,instr(SDO_GEOMETRY,',',1,&cnt)-1) Output from T
PRAZY@11gR2> /
Enter value for cnt: 2
OUTPUT
-6.33787700000002, 56.547309
Elapsed: 00:00:00.05And remember, while posting questions it is good to specify your DB version with clear sample data and required output.
HTH,
Prazy -
How to select only one record at a time in ALV
Hi all,
I have to use ALV report. Each record on the report output should have a button (or radio button) which will allow the record to be selected. My requirement is to select only one record at a time.
please guide me how to proceed further.
regards
manishhi
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sampleCheckBoxProgram
Regards
Pavan -
How to display only last 4 digits of tax number in Vendor Master view MK03
Dear experts,
In the Vendor Master view by Purchasing Organization (MK03), is there a way that will allow the user to view only the last four digits of the Vendor tax number?
For example: Display only **-*-6789 (or blank spaces), instead of 123-45-6789 ?
Any ideas and insights are much appreciated. Will award points for help.
-TWIn your report, just do a substr(ssn,5,4) for your new & improved SSN field to be displayed:
SELECT First,
Last,
SUBSTR(ssn,5,4),
Phone
FROM Employees
Thank you,
Tony Miller
Webster, TX -
JDBC: How to select only those records which contains col1 is NULL
Hi All,
In JDBC SELECT scenario.
I wants to select only those records which contains col1 is NULL.
I am trying as follows:
<key>
<col1 isNull="TRUE" />
</key>
but in moni/monitoring i am getting Following Error
006-12-01 19:35:20 Error Unable to execute statement for table or stored procedure. 'BG_SALARY_SEND_SAP_D' (Structure 'SELECT') due to java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
2006-12-01 19:35:20 Error Exception caught by adapter framework: Error processing request in sax parser: Error when executing statement for table/stored proc. 'BG_SALARY_SEND_SAP_D' (structure 'SELECT'): java.sql.SQLException: FATAL ERROR document format: structure 'SELECT', key element 'key' contains no values
Please suggest how to do select rows with col1 is null.
RegardsRohan,
isNull= true is used to make the KEY element not mandatory.
In your case, if the select query is
select emp from emptest where empno is null
, then the datatype will be,
<root>
<StatementName>
<dbTableName action=SELECT>
<table>emptest</table>
<access>
<emp></emp>
</access>
<key1>
<b><empno hasQuot="NO">is null</empno></b>
</key1>
</dbTableName>
</StatementName>
</root>
I dont have a DB access to try this, but I think this should work.
If this doesnt work, then you would need to use SQL_QUERY,
<root>
<StatementName>
<anyName action= SQL_QUERY>
<access>select emp from emptest where empno is null</access>
</anyName >
</StatementName>
</root>
http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm
Regards,
Bhavesh -
How to select only layers that are both, visible and not blocked in photoshop cc?
I used to do it in photoshop CS6 without any configuration, but now I can select only "not blocked" or "visible" layers? Can't I select both?
We will need to reformat your EXT, but it will then work on both Mac and Win
Connect the drive to your Mac, open disk utility
Go to the partiton tab and select '1' ... format should be ExFAT ... in options select MBR
Format the drive
It should now work on both OSs; report back -
Order by on the basis of last characters of the column
hi
i have this type of data in Column
ABL - Allied Corp. services (XES) - Newyork
ABL - Allied Corp. services (XES) - Chicago
SBS - Logistics - Newyork
ETC..
As the last characters are for city and i want to perform order by on the basis of city.The naming convention is "the name always contain two hiphens(-)
and the city name in the last".(means after second '-')
RegardsSQL> INSERT INTO dt_test VALUES('ABL - Allied Corp. services (XES) - Newyork');
1 row created.
SQL> INSERT INTO dt_test VALUES('ABL - Allied Corp. services (XES) - Chicago');
1 row created.
SQL> INSERT INTO dt_test VALUES('SBS - Logistics - Newyork');
1 row created.
SQL>
SQL> select
2 column_1
3 FROM
4 dt_test
5 ORDER BY
6 SUBSTR(column_1, INSTR(column_1,'-',1,2) + 2);
COLUMN_1
ABL - Allied Corp. services (XES) - Chicago
ABL - Allied Corp. services (XES) - Newyork
SBS - Logistics - Newyork -
How to seperate numbers and characters in a column
Hi,
In my database i have a table named birth.DBA prior to me created a column with data type var char,for which data type number must be allocated.Both characters and numbers are entered into that column.now i have to change my data type into number.how can i do this.
My idea is to first separate numbers and characters in that column.But how can i do this.can u please suggest.use regular expressions
SELECT regexp_replace('aa123','[[:digit:]]') from dual;
SELECT regexp_replace('aa123','[^[:digit:]]') from dual
hth
Marco -
How to select/unselect all checkbox in one column
Hi Experts,
I have a report with a column as check box. The query is like:
select apex_item.checkbox(1, ID) "update", ID, name, job
from a_table
So that user can select the rows they want to update.
Sometimes user wants to select all the rows. It's not easy to select all the rows one by one when there are many rows on the report.
So how to select/unselect all rows in this case?
Thanks,
DanielHi,
See if this post help
Re: Need Check All in Checkbox
Regards,
Jari -
How to get only updated records for a column using loading type INSERT
Hi,
Good morning all,
I have source1 containg 3 columns bill_cd,bill_desc,bill_date and
source2 has the columns bill_cd,bill_key,source_id.
My target has the columns bill_cd,bill_date,bill_desc .
Now the requirement is, bill_cd in target should not repeated when we run the mapping more than one thime. it should get only updated records not the previous records using only INSERT Loading type(for target) not to use update/insert.
How can we achieve this logic in mapping level.
Anybody Please give me some solution immediately.
Thanks in Advance,
SivThanks Herzog for your reply,
Here bill_cd is not unique. Yes,I want only new records using INSERT as loading type. Suppose when the map runs for the first time, bill_cd is loaded with values 1 to 5.
Now, in the source I have got new records 6 to 10 for bill_cd and when I run the mapping again I need to get only records for bill_cd from 6 to 10 using INSERT as loading type.
Is it possible to achieve this at mapping level?
Regards,
Siv. -
How to add only highest values in the column
Hello All,
We have report where I need to add only highest values in 'Price' column.
Ex:
Group Mat Price
Grp1 Mat1 50
Mat2 75
Mat3 100
Grp2 Mat1 50
Mat2 100
I need my result as 200...
Any input is appreciated!
Thanks in advance !!
Venu.Sriman/Surendra,
Unfortunately, this approach does not work because the Calculate Result As --> Maximum applies not only to the subtotals but also to the grand total. Therefore, the result in Venu's example will be:
MAX(Grp1) = 100
MAX(Grp2) = 100
MAX(All Grps) = 100
We have the same requirement as Venu, but have not found a satisfactory solution yet. The only way we have solved such problems in the past is to use VBA in workbooks, but the report we are using now is a Web report.
Hope this helps to clarify the issue...
Bob -
How to select the last elements in a string
Hi Guys
I am using UART RS232 protocol and i need to calculate the check sum. My data came in decimal and in the end it must be doubles to manipulate it. So my problem is, for example, the sum of all elemants is in decimal 1742 and in hex is 6CE and i wont only the last two elemants, CE that corresponds to 206 that is the result of my checksum. Can anyone help me?
Thanks
Solved!
Go to Solution.
Attachments:
String last elements.vi 9 KBThanks Syrpimp
My data came from HMI in decimal like the example that i show above. Each cell is a value. You used an array, but i think that i can't use it because it must be done automatically and the data field have variable length.
The UART protocol frame has a start frame field that corresponds to two ‘{‘ characters and an end frame field that corresponds to two ‘}’. Additionally, besides the data field, that has variable length, it has a byte that corresponds to the command type and another that is the checksum. The following table illustrates the protocol.
Bytes considered in checksum
Command Data
Start Frame
Cmd
(hex)
Data0
Data1
Data2
Data3
Data4
Data5
Data6
Data…
CHK SUM
End Frame
1 Byte CHK SUM (sum of all data bytes truncated to 1 byte)
Fig. 1 UART communication protocol template
I receive data like this:
123
123
160
54
111
103
110
108
107
109
108
108
100
100
100
100
0
0
1
4
5
0
0
0
0
0
0
7
96
1
0
0
0
0
0
10
51
1
0
0
51
1
1
23
12
0
206
125
125
I'm trying explain my doubt the best way i can and i thank you all.
Maybe you are looking for
-
Updated to 2.0, now my purchased music won't play
I can't seem to do a search since the search function for some reason has gone from the forums. I'd like to know if anyone has been able to get their purchased music to play. It will play fine on the computer but not on the iPod Touch. Information is
-
My TMG server cannot connect with Outlook .
I have TMG server connected with proxy server , i have added the record for email and added the IP address for my mail server ( outcoming , incoming ) now i can ping to the mail server but when i configure the outlook still cannot connect to your ser
-
LF TAPS cannot be invoiced with F2
Hello- I am receiving this message when I create a billing document. I am using item categories TAX (which is billable from the order) and TAPS (which is not billable) from material substitution. I have TAPS configured as not relevant for billing.
-
I downloaded the New numbers iOS and now i can't open any numbers documents
I just recently downloaded the new Mavricks update and now all my numbers Documents say i need to download the new system before opening. I alread have the new numbers system so i am unsure of what I need to do to fix it. I use numbers all day for my
-
Hi Gurus I made some changes in info source in BW DEV with some infoobjects. unfortunately those fields are not there in data source . So removed those changes from info source. now when I have activated it again the routines written in original info