logo
down
shadow

Insert into a table using multiple tables


Insert into a table using multiple tables

By : user2172821
Date : October 22 2020, 08:10 PM
like below fixes the issue Assuming you already create the table AppFact with PK AppFactID, the query you're looking for is:
code :
INSERT INTO AppFact (Category, Rating, Reviews, Installs, Price, Content_Rating)
SELECT c.CategoryID, a.Rating, a.Reviews, i.Installs, a.Price, r.ContentRatingID
FROM googleplaystore a
    INNER JOIN DimContentRating r ON a.Content_Rating = r.Content_Rating
    INNER JOIN DimCategory c ON a.Category = c.Category
    INNER JOIN DimInstalls i ON a.Installs = i.Installs


Share : facebook icon twitter icon
One Stored Procedure to insert one table and retrieve ID and insert multiple tables

One Stored Procedure to insert one table and retrieve ID and insert multiple tables


By : Yren Delvalle
Date : March 29 2020, 07:55 AM
Hope this helps I have 3 tables and columns. ex: Green (userID, Name, Address), Red (userID, TemproraryAddress), Blue (userID, WorkPlace).
code :
DECLARE @userID INT;
INSERT dbo.Green(Name, Address) SELECT @name, @address;
SELECT @userID = SCOPE_IDENTITY();
INSERT dbo.Red(UserID, TemporaryAddress) SELECT @userID, @something;
INSERT dbo.Blue(UserID, WorkPlace) SELECT @userID, @something_else;
Insert multiple data into two tables and need to insert the last inserted id into another table

Insert multiple data into two tables and need to insert the last inserted id into another table


By : Youvraj
Date : March 29 2020, 07:55 AM
wish helps you For the latest problem you posted. You are calling obj.test method only once after all the if blocks.
So the "course" variable will have value from the latest if block where the condition is true.
code :
string course = "";
string Name = schName.Text;
scholarshipBLL obj = new scholarshipBLL();

List<addScholarship> addScholarshipList= new List<addScholarship>();

addScholarship scholarship;
if (DIT.Checked )
{
    scholarship = new addScholarship(Name,course);
    addScholarshipList.Add(insertedName);
    course = "DIT";
    DataTable dt = obj.test(Name, course);

}

if (DFI.Checked)
{
    scholarship = new addScholarship(Name,course);
    addScholarshipList.Add(insertedName);
    course = "DFI";
    DataTable dt = obj.test(Name, course);

}
I am trying to insert values into a table from multiple tables (table relationships are shown)

I am trying to insert values into a table from multiple tables (table relationships are shown)


By : getwell3
Date : March 29 2020, 07:55 AM
hope this fix your issue Got rid of cross join section. switched FormId and OrderKey to the variables @FormId and @OrderKey and filled in these two variables with the variables I defined earlier in the code: NextNaftaId and OrderKey
New code looks like this:
code :
    Dim cmd1 As New SqlCommand("Insert into FormLineTable (FormID, OrderKey, LineId, ShipmentNumber, PartNumber) Select @FormID, @OrderKey, ShipmentLineNumber, ShipmentNumber, PartNumber FROM ShipmentLineTable", con)
    cmd1.Parameters.Add("@FormID", SqlDbType.Int).Value = NextFormID
    cmd1.Parameters.Add("@OrderKey", SqlDbType.Int).Value = OrderKey
Insert first table into temp table when procedure returns multiple tables in SQL Server 2014

Insert first table into temp table when procedure returns multiple tables in SQL Server 2014


By : Lambert Moonshine
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have 2 procedures proc_Data, proc_FetchData. , To insert only the first table you can use OPENROWSET.
code :
create procedure proc_FetchData
As
Begin    
    declare @userData TABLE(Data NVARCHAR(30))
    INSERT INTO @userData
    SELECT * FROMOPENROWSET('SQLNCLI','Server=[server];Trusted_Connection=yes;','EXEC [database name].dbo.proc_Data')    
select * from @userData
end
How to insert from another table and using PK to insert into multiple tables in SQL Server?

How to insert from another table and using PK to insert into multiple tables in SQL Server?


By : Sebastiaan Vreeken
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You should realize that your code can create more than one new record.
The following captures all the new ids into @ids and then inserts all of them into the new table:
code :
declare @ids table (int id);

insert into table1(a, b) 
    output inserted.id into @ids
    select a, b 
    from TempTable;

insert into Table2(id, description) 
    select id, 'Test'
    from @ids;
Related Posts Related Posts :
  • SQL Query - Group consecutive items based on condition
  • Users who work in same department
  • Syntax error near column value Vb
  • Oracle Trigger BEFORE INSERT has No data found
  • What kind of join to use on SQL tables
  • Is there a way to add a constant value dynamically to all records returned in Hive?
  • SQL optimization (inner join or selects)
  • EF 6.x, LINQ-to-SQL and raw SQL clauses
  • Simple SQL Variable Assignment Only Returns One Letter: Why?
  • Converting a custom timestamp to date
  • SQL Server : inserting Player vs Player names in to new table from tblEntrants
  • invalid identifier in sql
  • PL/SQL - I keep getting this error when concatenating: PLS-00306: wrong number or types of arguments in call to '||'
  • Count records only from left side of a LEFT JOIN
  • get everything before a string including itself oracle
  • Format Data from Word Doc to SQL using RegEX
  • Conditional formatting on MAX value row
  • MS-Access : selecting data from two tables and only returning you need
  • SQL Server: optimal indexing strategies for many-to-many join
  • DBgrid column very wide
  • PostgreSQL Group values by category, count and calculate percentage
  • MS Access SQL - Most Recent Record for Each Consultant ID
  • Update table: Summary of previous rows without using cursor or while loop
  • PostgreSQL: built-in function to remove substring starting with certain pattern
  • ORA-00909: invalid number of arguments
  • How to summarize all possible combinations of variables?
  • Select Column within a Column SQL
  • PostgreSQL Inserting 2 relationships at once
  • T sql - How to store results from a dynamic query using EXEC or EXECUTE sp_executesql
  • How do I parse my json into CSV using regex?
  • Reverse foreign key cascading (or how to collect database garbage)
  • SQL Pivot Questions
  • Insert records into a table with a condition in SQL Server 2016
  • display null value using rank functions in oracle sql
  • SQL - Get count of group by column but also select top item of group
  • How to add an array of datarows into an exisitng table inside my database
  • There is no unique constraint matching given keys for referenced table "employee" 1
  • SQL: Unable to SELECT joined column
  • How to find out how much space a SQL Server table uses?
  • Window function to remove specific records from SQL Server dataset
  • How to add a column for each day in sql?
  • Create group column based on the specific rows
  • Not sure if this consistitues a transitive dependency
  • How to compare the values in a column to a long list in SQL Server
  • Preserving data format Decimal(6,5) from vba to sql
  • Oracle Query to rollup QTY by Year- only last 3 years
  • SQL - Calculate 2 columns and view result to another to column
  • Divide or Multiply according to a condition (Improving query)
  • PostgreSQL unnest() with consecutive integers grouped by number
  • SQL to limit output to certain months and years
  • VARCHAR TIME TO GET THE DIFFERENCE
  • SQL conditional constraint on multiple columns being unique
  • Optimize a SQL select query in a loop
  • BTEQ Teradata Import Multiple files into one table
  • Update SQL datetime column with oldest values of another table column?
  • Is INSERT ... SELECT an atomic transaction?
  • SQL query completed successfully but not results
  • SQL sub select returning multiple values
  • Verify condition on two columns
  • SQL conditional field, first match JOIN
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org