change specific data of column - sql

I have a table in which 10 record, now i want to update specific column data, means some part some column data and some not, for example in row 1 i want to change std with standard and other data will remain same, change same thing in all row in a single query. can it will be possible? and remember we cant remove and add cell again because it will change id
id - col1 - col2
1 - A - std abcad
2 - B - std bcddsad
3 - C - std avadsad
4 - A - std abcdsad
5 - B - std bcddsa
6 - C - std avadsad
7 - A - std abcdsd
8 - B - std bcddsds
9 - C - std avadsd

You can use the replace function for this
Update
table
Set
col2 = Replace(col2, 'std', 'standard');

UPDATE tblName
SET Column .WRITE('Standard',(CHARINDEX('std',Column,1)-1),LEN('std'))

Related

Datastage Column Mapping logic Based on column Value (Or any SQL function to do the same)

I'm trying to find a solution in datastage (Or in SQL) - without having to use a bunch of if/else conditions - where I can map value of one column based on value of another column.
Example -
Source File -
ID
Header1
Value1
Header2
Value2
1
Length
10
Height
15
2
Weight
200
Length
20
Target Output -
ID
Length
Height
Weight
1
10
15
2
20
200
I can do this using Index/Match function of excel. Was wondering if datastage or Snowflake can look into all these fields similarly and automatically populate the value column to the corresponding header column!
I think the best solution in DataStage would be a Pivot stage followed by a Transformer stage to strip out the hard-coded source column names.

SUMIF MATCH Conditional in Python

I'm trying to use a python version of excel MATCH, INDEX and SUMIF.
Example dataset:
A - 1
B - 2
A - 5
C - 6
A - 1
C - 2
So if I need to sum A it should output 7.
The issue is that I don't know the variable A - I need to use some universal variable that captures all values. So read out A = 7, B = 2, C = 8.

How to use index match when you have 2 values?

I have a list with 300 names codes and each of these names have more than 1 value, e.g.,
CODE - VALUE
300 - 1
300 - 2
300 - 3
400 - 1
400 - 2
For each code, I want to return the greatest value, and after that I want to transform this greatest value into his name, e.g.,
CODE - VALUE - NAME
300 - 1 - alpha
300 - 2 - beta
300 - 3 - gamma
400 - 1 - theta
400 - 2 - sigma
So for code “300” I want to return “gamma” and for code “400” I want to return “sigma”.
Any thoughts?
Regards
place the following formula in F1 and the code you are looking for in E1. This assumes your second table is located in A1:C5. Adjust ranges to suit your data. Avoid full column references within the aggregrate function.
=INDEX(C:C,AGGREGATE(14,6,ROW(A1:A5)/((A1:A5=E1)*(B1:B5=AGGREGATE(14,6,B1:B5/(A1:A5=E1),1))),1))

Extracting a word from string from n rows and append that word as a new col in SQL Server

I have got a data set that contains 3 columns and has 15565 observations. one of the columns has got several words in the same row.
What I am looking to do is to extract a particular word from each row and append it to a new column (i will have 4 cols in total)
The problem is that the word that i am looking for are not the same and they are not always on the same position.
Here is an extract of my DS:
x y z
-----------------------------------------------------------------------
1 T 3C00652722 (T558799A)
2 T NA >> MSP: T0578836A & 3C03024632
3 T T0579010A, 3C03051500, EAET03051496
4 U T0023231A > MSP: T0577506A & 3C02808556
8 U (T561041A C72/59460)>POPMigr.T576447A,C72/221816*3C00721502
I am looking to extract all the words that start with 3Cand are 10 characters long and then append the to a new col so it looks like this:
x y z Ref
----------------------------------------------------------------
1 T 3C00652722 (T558799A) 3C00652722
2 T NA >> MSP: T0578836A & 3C03024632 3C03024632
3 T T0579010A, 3C03051500, EAET03051496 3C03051500
4 U T0023231A > MSP: T0577506A & 3C02808556 3C02808556
8 U >POPMigr.T576447A,C72/221816*3C00721502 3C00721502
I have tried using the Contains, Like and substring methods but it does not give me the results i am looking for as it basically finds the rows that have the 3C number but does not extract it, it just copies the whole cell and pastes is on the Ref column.
SQL Server doesn't have good string functions, but this should suffice if you only want to extract one value per row:
select t.*,
left(stuff(col,
1,
patindex('%3C[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%', col),
''
), 10)
from t ;

Compare Values in Excel in all sheets that have the same title/name

Hello fellow netizens of the programming community!
Need some help with a couple of excel worksheets that I'll be working forth day in and out.
Here's a some info of what I have on hand, and what I want to do..
I have several worksheets (10 of them) of similar (not 100% identical) tables ..
one worksheet may look like this (x, y and z are other unimportant variables)
name - score - x - y - z
jon - 50 - x - y - z
sam - 50 - x - y - z
pad - 50 - x - y - z
fed - 50 - x - y - z
mum - 50 - x - y - z
and another worksheet may look like this
name - score - x - y - z
pad - 50 - x - y - z
mum - 50 - x - y - z
fed - 50 - x - y - z
jon - 50 - x - y - z
sam - 50 - x - y - z
simply put, there are names such as 'jon' and the relevant scores that can occur across all the worksheets, or names such as 'ped' that can only appear once in one worksheet.
I would like to compare all the sheets at the same time, finding out the highest score for jon, sam, pad, fed, mum across all the sheets and have these information presented in another new sheet itself.
for e.g.
the new sheet should present data as
name - highest score
jon - 39
sam - 22
pad - 42
mum - 22
I hope whatever I'm trying to say is not confusing anyone! If anyone could help, ill greatly appreciate it!
The solution is available via pivot table formed across multiple sheets.
Steps:
Assuming your files is open, and you are in one of your sheets.
Alt+D+P (Opens a dialog box)
Select "Multiple consolidation ranges" and "Pivottable" >>Next
Select "Create a single page field for me" >>Next
Here, select in the Range box and Add, all the table areas one by one. Have one addition per sheet of yours. So you should have 10 ranges getting inserted here. >>Finish
You will get a pivot table where the Values field will have "Count of score" (it is mostly this, else it could be Sum of score, etc. Here's how you change it to max) Click on whatever is in the values field >> Value Field Settings >> Max >> Ok.
(If you want to choose min/average/count/product/stdDev, this is the place to make that change)
As a caveat, do check fields in Filters/Columns/Rows are as you want. I have run a sample pivot on the two tables you have provided, screenshot is attached, this is how the table should look like.
Sample Pivot screenshot on data provided