Populating column in SQL with multiplication based on existing column - sql

I'm trying to create a new column in my SQL table that contains a simple multiplication based on an existing column.
Example of the existing table:
Product
PricingUSD
Product A
20
Product B
40
What I want to do:
Product
PricingUSD
PricingEUR
Product A
20
20.48
Product B
40
40.96
I created the new column with:
ALTER TABLE table
ADD 'PricingEUR' NUMERIC(10);
But now I'm not sure how to populate the new column (it is populated with NULL). It needs to take the number from "PricingUSD" and multiply it by 1.08.
I believe it would be related to INSERT TO, so I tried
INSERT INTO table (PricingEUR)
VALUES (PricingUSD*1.08);
Also tried many variations based on tutorials but none worked. Thoughts?

Related

Insert distinct values from another table's column on to a new table BigQuery

I am trying to write a BigQuery to get distinct values from one table say ABC
select distinct name from dataset.abc
1
2
3
4
now I want to insert these values to another table say XYZ, which also contains column as name and another column as company.
Note: the company column can be duplicated as I want the to have all 4 rows against every company to be inserted in table ABC.
I need a BigQuery to do this dynamically instead of updating every dataset manually every time.
P.S. Sorry if my question is not as per standards as this is the first time I am posting on Stackoverflow.

I'm trying to make a generated column in one table, that contains the number of rows there are in another table

Let's say I have table A and table B. Table B needs to have a column "atr1" that counts how many rows there are in table B and also the number of columns can't exceed a constant number that's specified in another column in table B called "atr2".
I tried doing this:
alter table B
alter column atr1 type integer generated always as(count(*) from A) check (atr1 < atr2) not null;
but it gives me a syntax error at or near generated.
Generated columns can only refer to calculations on columns in the table itself. If you need to know the count from a different table, you will need to create a view instead.

Comparison of two tables based on a cross reference of columns in SQL Server

My question is about comparison of fields based on the mapping table SQL Server. In the attached image, I wanted to compare values of Table 1 and Table 2 based on the mapping provided in Table 3. For example, we need to check values of Table 1's Field 1 with Table 2's Field_3_New and other columns likewise. Mapping of these columns to compare is placed in Table 3.
I want to check, whether Table 1's Field 1 values are matching with Table 2's Field 3_NEW's values or not. We came to know that Table 1's Field 1 values have a match with Table 2's Field 3_New values based on the field mapping provided in Table 3. The above is an example scenario, I'm dealing with 40 odd fields like this.

How to replicate records using PLSQL in two tables

I have two existing tables and many records already added.
formula(formulaId,formulaName,formulaType)
and formula_detail(detailId,formulaId,fieldType,value)
Now there is change in formula table and new column is being added , branchId as
formula(formulaId,formulaName,formulaType,branchId),
and branch table is branch(branchId,branchName)
I want to copy and paste every existing record in formula table for every branch.
e.g if there are 3 existing records in formula table (with ID 1,2,3) and 2 branches. Then copy paste operation should produce total new (3*2)=6 records in formula table and also replicate records in formula_detail table for every newly created formula as follows
for formulaId 1 , If there were 5 records in formula_detail table, then copy paste in formual_detail table will have (2*5) new records added in formual_detail table.
I tried some solutions but number of are records huge and script is taking time. Please help. If need any test code I can add.
First of all replicating same column in detail table is against the Normalized Form used in your Data model.
Still If you want to add the column anyway,
Add the column using ALTER statement in formula_detail table
Try using this Merge statement
.
MERGE INTO formula_detail fd
USING (SELECT formulaId, branchId from Formula) temp
ON (fd.formulaId=temp.formulaId)
WHEN MATCHED THEN
UPDATE SET fd.branchId=temp.branchId;

How to take look up values from a look up table using SSIS

I have a scenario as described below need to create a SSIS Package for that.
I have 3 COLUMNS in source table which needs to be entered in destination table.
But all these columns has to be looked up in the look up table of destination database and then enter their ID's in the destination column.
For example
Source table has 3 columns with values
idnum static type timedimension geography modified date
1 price daydate france 8/12/2015
2 RetailpRICE WEEK ITALY 9/12/2014
I want a package which looks up the column values with the matchin ID and populates in the destination table...
I know we can use the LOOKUP transform to update the data for one single column in destination table what about the other columns which I need to insert along with the lookup insertion.
How can I achieve this ? Also is there a way to pull only the recent data from the source table using modified date column values
Use a different lookup for each lookup table that you need to reference to get the Ids. So if each of your columns that you want IDs for gets its ID from a different table, then you need to use three lookups, one after the other, until you have all three IDs.