Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql select and insert from the same table

Posted on 2013-12-06
3
Medium Priority
?
376 Views
Last Modified: 2013-12-07
HI,

I have the code below but it creates duplicates.
I want to be able to select the values from the mastercompany and insert it into the same table but with a different company id.

Would be grateful for any advice

Insert into tbl_M08_PageObjectLangContent
(pageObjLangContId, objectId, companyId, sysLanguageId, objectText, objectAlign, createdBy, createdDate, lastModifiedBy, lastModifiedDate)
(SELECT newid(), objectId, 'c6a21d21-a55a-4d50-a4a7-10c5a746460d', sysLanguageId, objectText, objectAlign, 'b81ff3cc-811f-49c8-ab22-9d9fc377d0f5', createdDate, 'b81ff3cc-811f-49c8-ab22-9d9fc377d0f5', lastModifiedDate
FROM tbl_M08_PageObjectLangContent
WHERE companyId = '141a9a54-a3ab-440f-91c1-38eb16310b26')
0
Comment
Question by:Soluga
3 Comments
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39701542
instead of selecting companyID from the table, this is where you would add the new companyid that you want the record to have.. is the new  company id available in a table, if so select it from there
0
 
LVL 15

Accepted Solution

by:
JimFive earned 2000 total points
ID: 39702152
I assume you mean that you want to add it if it doesn't already exist for the new company.

So you add
AND NOT EXISTS (SELECT * FROM tbl_M08_PageObjectLangContent t2 WHERE tbl_M08_PageObjectLangContent.objectid = t2.objectID
AND t2.companyID =  'c6a21d21-a55a-4d50-a4a7-10c5a746460d')

Open in new window

0
 
LVL 1

Author Closing Comment

by:Soluga
ID: 39702958
That's great thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question