Using Regexp_substr to display specific text - sql

I have a column called keys with data in this format:
qwert! B1 12345! B3 abcde! B4 fgh14777
stat! B3 3456! C0 224466! B2 bbmm
I'm trying to use regexp_substr to display only text that starts with B3 and end with a character before the next exclamation mark (!)
So my desired result would be this:
B3 abcde
B3 3456
B3 might be be on any position within the string and the length of the text might vary as well. Not every row contains B3.
Any help would be appreciated!

This is a pretty simple regular expression:
select regexp_substr('qwert! B1 12345! B3 abcde! B4 fgh14777', 'B3[^!]+', 1, 1)
from dual

Related

split value based on length and delimiter - vba

Can any one help me on VBA script on split paragraph into difference cells with delimiter space and maximum character of 30 for each cell
Example
Split value in Cell A1 to A3 and A4
A1 ='I will not make the same mistake again' (38 Character)
A3 = 'I will not make the same' (24 Character)
A4 = 'mistake again' (13 Character)`
Thank in advance

For Excel VBA, If B2 value did not change then A2 will keep same, If B2 is changed then A2 will increase by one

I need a VBA for the whole column B and A says that
if Value of Cell B2 did not change then A2 value will be the same
if B2 value is changed then A2 value will increase by one
Use this formula.
Put your staring number in A1.
Put this in A2:
=IF(B2<>B1,A1+1,A1)
And copy down.

Trying to compare two strings in excel

I have something like this:
A1: 0069
B1: 030069
In every case, I need to check if A1 is equal to B1 if I were to ignore the 03. I have a lot of cells, and the 03 is just there because its the format of the data. However, A1 can be multiple different lengths, so I can't just use the MID formula and just check B1 after the 03 because I would need to make multiple cases depending on how long A1 is.
Originally, I get the A1 data by using the formula:
D1 =FIND("-",C1), where C1 is A1 in the format: 0069-XXXX-XX.
I then use:
A1 =LEFT(C1,D1-1), which gives me the number 0069 as you see above. This way, I'll always have the correct length when I actually start the real problem.
My question is, can I use some kind of concatenation to just add a 03 to A1 and then see if it is equal to B1. I've tried using & and CONCATENATE, but because they are in general terms, I get the #VALUE error. Maybe I'm just not typing it in correctly, but yea.
Thanks!
You can just use & correctly in A1:
="03" & LEFT(C1, D1 - 1)
To compare these values you could use a formula like below:
=IF(A1=RIGHT(B1;4);"true";"false")
Actually it is not necessary to use the formula in A1 nor D1, you can use your data from column C straight away:
=IF(LEFT(C1;4)=RIGHT(B1;4);"true";"false")
If the pattern is Column C is nnnn-XXXX-XX then no helper column (Columns A and D) is necessary:
=MID(B1,3,4)=LEFT(C1,4)

VBA Resize Array, 1 Column to 4 Columns

So I copied some data into Excel, but unfortunately for me when I pasted the data the chart format sorta died, so I ended up with a 1 column full of data(Column A). Basically A1 is suppose to be Movie name, A2 is suppose to be in B1(Cost of movie), A3 is suppose to be in C1(How long is the movie), and A4 is suppose to be in D1(Sequel:yes/no). And A5 is suppose to be in A2, A6 in B2, A7 in C2, A8 in D2, A9 in A3, A10 in B3..etc.. Its suppose to be a chart with 4 columns, but everything ended up in column A. Anyone can help me write a VBA code to rewrite the first column back to 4 columns? Thanks in advance.
No need for VBA. In excel, use INDIRECT in the four columns
=indirect("A"&(row()-1)*4+1) | =indirect("A"&(row()-1)*4+2) | ...
=indirect("A"&(row()-1)*4+1) | =indirect("A"&(row()-1)*4+2) | ...
...

how to transpose in sql

Suppose I have
select *
from A a
left outer join B b on b.ID in (1,2,3/*and possibly any numbers*/)
and so I get (Ax - A's xth row, Bx - B's xth row):
A1 B1
A1 B2
A1 B3
A2 B1
...
And what I want is this:
A1 B1 B2 B3
A2 B1 B2 B3
So that there is dynamic number of columns. What is the best way of achieving this?
It is possible using Pivots.
The below link might help you. It contains 4-5 different solutions.
Tranpose in SQL Server