Inserting rows from one table to another where match occurs The Next CEO of Stack OverflowInsert into … values ( SELECT … FROM … )Best way to get identity of inserted row?How to concatenate text from multiple rows into a single text string in SQL server?Select columns from result set of stored procedureSQL update from one Table to another based on a ID matchInserting multiple rows in a single SQL query?Insert results of a stored procedure into a temporary tableSelect n random rows from SQL Server tableSQL Server: How to Join to first rowHow to select rows with no matching entry in another table?

How to start emacs in "nothing" mode (`fundamental-mode`)

Trouble understanding the speech of overseas colleagues

How easy is it to start Magic from scratch?

Why Were Madagascar and New Zealand Discovered So Late?

Whats the best way to handle refactoring a big file?

Anatomically Correct Mesopelagic Aves

How to make a software documentation "officially" citable?

Removing read access from a file

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Why is there a PLL in CPU?

Anatomically Correct Strange Women In Ponds Distributing Swords

How to write the block matrix in LaTex?

Too much space between section and text in a twocolumn document

What does this shorthand mean?

How long to clear the 'suck zone' of a turbofan after start is initiated?

What can we do to stop prior company from asking us questions?

Implement the Thanos sorting algorithm

Visit to the USA with ESTA approved before trip to Iran

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Customer Requests (Sometimes) Drive Me Bonkers!

Return of the Riley Riddles in Reverse

Why does GHC infer a monomorphic type here, even with MonomorphismRestriction disabled?

How to safely derail a train during transit?

How to use tikz in fbox?



Inserting rows from one table to another where match occurs



The Next CEO of Stack OverflowInsert into … values ( SELECT … FROM … )Best way to get identity of inserted row?How to concatenate text from multiple rows into a single text string in SQL server?Select columns from result set of stored procedureSQL update from one Table to another based on a ID matchInserting multiple rows in a single SQL query?Insert results of a stored procedure into a temporary tableSelect n random rows from SQL Server tableSQL Server: How to Join to first rowHow to select rows with no matching entry in another table?










-1















I have two tables PRODUCTION_HISTORY and BULK_INSERT. I am trying to insert values from TEST_Custom_DataSets column from BULK_INSERT table to CUSTOM_DATASETS in the PRODUCTION_HISTORY table where the WELL_KEY matches but I am getting the following error:




The multi-part identifier "dbo.PRODUCTION_HISTORY.WELL_KEY" could not be bound.




Following is my query:



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS)
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT]
WHERE [dbo].[BULK_INSERT].WELL_KEY = dbo.PRODUCTION_HISTORY.WELL_KEY


Any advice would be greatly appreciated!










share|improve this question



















  • 1





    Use a join in your select statement.

    – Sean Lange
    Mar 21 at 16:35











  • I don't see table dbo.PRODUCTION_HISTORY in your query.

    – Eric
    Mar 21 at 16:54















-1















I have two tables PRODUCTION_HISTORY and BULK_INSERT. I am trying to insert values from TEST_Custom_DataSets column from BULK_INSERT table to CUSTOM_DATASETS in the PRODUCTION_HISTORY table where the WELL_KEY matches but I am getting the following error:




The multi-part identifier "dbo.PRODUCTION_HISTORY.WELL_KEY" could not be bound.




Following is my query:



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS)
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT]
WHERE [dbo].[BULK_INSERT].WELL_KEY = dbo.PRODUCTION_HISTORY.WELL_KEY


Any advice would be greatly appreciated!










share|improve this question



















  • 1





    Use a join in your select statement.

    – Sean Lange
    Mar 21 at 16:35











  • I don't see table dbo.PRODUCTION_HISTORY in your query.

    – Eric
    Mar 21 at 16:54













-1












-1








-1








I have two tables PRODUCTION_HISTORY and BULK_INSERT. I am trying to insert values from TEST_Custom_DataSets column from BULK_INSERT table to CUSTOM_DATASETS in the PRODUCTION_HISTORY table where the WELL_KEY matches but I am getting the following error:




The multi-part identifier "dbo.PRODUCTION_HISTORY.WELL_KEY" could not be bound.




Following is my query:



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS)
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT]
WHERE [dbo].[BULK_INSERT].WELL_KEY = dbo.PRODUCTION_HISTORY.WELL_KEY


Any advice would be greatly appreciated!










share|improve this question
















I have two tables PRODUCTION_HISTORY and BULK_INSERT. I am trying to insert values from TEST_Custom_DataSets column from BULK_INSERT table to CUSTOM_DATASETS in the PRODUCTION_HISTORY table where the WELL_KEY matches but I am getting the following error:




The multi-part identifier "dbo.PRODUCTION_HISTORY.WELL_KEY" could not be bound.




Following is my query:



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS)
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT]
WHERE [dbo].[BULK_INSERT].WELL_KEY = dbo.PRODUCTION_HISTORY.WELL_KEY


Any advice would be greatly appreciated!







sql sql-server tsql bulkinsert






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 16:36









Andrea

7,781144954




7,781144954










asked Mar 21 at 16:30









AlexAlex

1




1







  • 1





    Use a join in your select statement.

    – Sean Lange
    Mar 21 at 16:35











  • I don't see table dbo.PRODUCTION_HISTORY in your query.

    – Eric
    Mar 21 at 16:54












  • 1





    Use a join in your select statement.

    – Sean Lange
    Mar 21 at 16:35











  • I don't see table dbo.PRODUCTION_HISTORY in your query.

    – Eric
    Mar 21 at 16:54







1




1





Use a join in your select statement.

– Sean Lange
Mar 21 at 16:35





Use a join in your select statement.

– Sean Lange
Mar 21 at 16:35













I don't see table dbo.PRODUCTION_HISTORY in your query.

– Eric
Mar 21 at 16:54





I don't see table dbo.PRODUCTION_HISTORY in your query.

– Eric
Mar 21 at 16:54












2 Answers
2






active

oldest

votes


















1














Pretty sure you just need to join those two tables together in your select statement.



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS) 
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT] AS bi
JOIN dbo.PRODUCTION_HISTORY AS ph
ON bi.WELL_KEY = ph.WELL_KEY





share|improve this answer

























  • So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

    – Alex
    Mar 21 at 17:16


















0














I suspect you want update, not insert:



UPDATE ph
SET CUSTOM_DATASETS = bi.Test_Custom_DataSets
FROM [dbo].[PRODUCTION_HISTORY] pn JOIN
[dbo].[BULK_INSERT] bi
ON bi.WELL_KEY = pn.WELL_KEY;





share|improve this answer























  • Thanks it worked!

    – Alex
    Mar 21 at 17:58











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285116%2finserting-rows-from-one-table-to-another-where-match-occurs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Pretty sure you just need to join those two tables together in your select statement.



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS) 
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT] AS bi
JOIN dbo.PRODUCTION_HISTORY AS ph
ON bi.WELL_KEY = ph.WELL_KEY





share|improve this answer

























  • So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

    – Alex
    Mar 21 at 17:16















1














Pretty sure you just need to join those two tables together in your select statement.



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS) 
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT] AS bi
JOIN dbo.PRODUCTION_HISTORY AS ph
ON bi.WELL_KEY = ph.WELL_KEY





share|improve this answer

























  • So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

    – Alex
    Mar 21 at 17:16













1












1








1







Pretty sure you just need to join those two tables together in your select statement.



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS) 
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT] AS bi
JOIN dbo.PRODUCTION_HISTORY AS ph
ON bi.WELL_KEY = ph.WELL_KEY





share|improve this answer















Pretty sure you just need to join those two tables together in your select statement.



INSERT INTO [dbo].[PRODUCTION_HISTORY] (CUSTOM_DATASETS) 
SELECT Test_Custom_DataSets
FROM [dbo].[BULK_INSERT] AS bi
JOIN dbo.PRODUCTION_HISTORY AS ph
ON bi.WELL_KEY = ph.WELL_KEY






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 21 at 16:39









Arnaud Peralta

977718




977718










answered Mar 21 at 16:37









Sean LangeSean Lange

26k21935




26k21935












  • So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

    – Alex
    Mar 21 at 17:16

















  • So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

    – Alex
    Mar 21 at 17:16
















So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

– Alex
Mar 21 at 17:16





So it executed well but also updated all the nulls all the way up to 76k rows. Is there a way to only update the ones that have well_key data not as null? thanks

– Alex
Mar 21 at 17:16













0














I suspect you want update, not insert:



UPDATE ph
SET CUSTOM_DATASETS = bi.Test_Custom_DataSets
FROM [dbo].[PRODUCTION_HISTORY] pn JOIN
[dbo].[BULK_INSERT] bi
ON bi.WELL_KEY = pn.WELL_KEY;





share|improve this answer























  • Thanks it worked!

    – Alex
    Mar 21 at 17:58















0














I suspect you want update, not insert:



UPDATE ph
SET CUSTOM_DATASETS = bi.Test_Custom_DataSets
FROM [dbo].[PRODUCTION_HISTORY] pn JOIN
[dbo].[BULK_INSERT] bi
ON bi.WELL_KEY = pn.WELL_KEY;





share|improve this answer























  • Thanks it worked!

    – Alex
    Mar 21 at 17:58













0












0








0







I suspect you want update, not insert:



UPDATE ph
SET CUSTOM_DATASETS = bi.Test_Custom_DataSets
FROM [dbo].[PRODUCTION_HISTORY] pn JOIN
[dbo].[BULK_INSERT] bi
ON bi.WELL_KEY = pn.WELL_KEY;





share|improve this answer













I suspect you want update, not insert:



UPDATE ph
SET CUSTOM_DATASETS = bi.Test_Custom_DataSets
FROM [dbo].[PRODUCTION_HISTORY] pn JOIN
[dbo].[BULK_INSERT] bi
ON bi.WELL_KEY = pn.WELL_KEY;






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 21 at 17:31









Gordon LinoffGordon Linoff

791k35316419




791k35316419












  • Thanks it worked!

    – Alex
    Mar 21 at 17:58

















  • Thanks it worked!

    – Alex
    Mar 21 at 17:58
















Thanks it worked!

– Alex
Mar 21 at 17:58





Thanks it worked!

– Alex
Mar 21 at 17:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285116%2finserting-rows-from-one-table-to-another-where-match-occurs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?