Solved

sql select and insert from the same table

Posted on 2013-12-06
3
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

734 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