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
Related
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
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.
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)
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) | ...
...
this is simple demo of what i want to do. I want to set a formula to a range of cells(eg. C1 to C10).
Range("C1").Formula = "=A1+B1"
but how to make formula use dynamic cells like this:
Range("C1:C10").Formula = "=Ax+Bx"
so in reality it is like,
C1 = A1 + B1
C2 = A2 + B2
C3 = A3 + B3
C4 = A4 + B4
C5 = A5 + B5
...
C10 = A10 + B10
how to change RHS of this formula to make above working: Range("C1:C10").Formula = "=Ax+Bx"
Range("C1:C10").Formula = "=A1+B1"
Simple as that.
It autofills (FillDown) the range with the formula.
I think this is the simplest answer possible: 2 lines and very comprehensible. It emulates the functionality of dragging a formula written in a cell across a range of cells.
Range("C1").Formula = "=A1+B1"
Range("C1:C10").FillDown
I would update the formula in C1. Then copy the formula from C1 and paste it till C10...
Not sure about a more elegant solution
Range("C1").Formula = "=A1+B1"
Range("C1").Copy
Range("C1:C10").Pastespecial(XlPasteall)
Use FormulaR1C1:
Cells((1,3),(10,3)).FormulaR1C1 = "=RC[-2]+RC[-1]"
Unlike Formula, FormulaR1C1 has relative referencing.
Use this
Sub calc()
Range("C1:C10").FormulaR1C1 = "=(R10C1+R10C2)"
End Sub