none
pull data from table A and insert into the same table

    Question

  • Hi All,

    When I pull data from one table and try to insert into the same table, is it possible for any erroneous data loading?

    ex:

     

    Insert Into TableA

    Select Cat,Bank, City, Act

    From TableA A CROSS APPLY (SELECT COUNT(ACT) AS TOT from TableA ) B

     

    Thanks

           


    shamen
    Monday, August 30, 2010 11:01 PM

Answers

  • > COUNT(ACT) AS TOT

    You are not doing anythig with TOT?

    Plain self insert should go without any issue.

    If you do some operation, like calculation, and insert,  that can have some issues.

    Plain self insert demo follows:

    -- SQL Server table self-insert demo
    USE tempdb;
    SELECT ProductNumber, ProductName=name, ListPrice 
    INTO ProdShort FROM AdventureWorks2008.Production.Product
    GO
    -- (504 row(s) affected)
    
    INSERT ProdShort SELECT * FROM ProdShort
    -- (504 row(s) affected)
    INSERT ProdShort SELECT * FROM ProdShort
    -- (1008 row(s) affected)
    INSERT ProdShort SELECT * FROM ProdShort
    -- (2016 row(s) affected)
    

    Kalman Toth, SQL Server & Business Intelligence Training; SQL 2008 GRAND SLAM
    • Proposed as answer by Atif-ullah Sheikh Tuesday, August 31, 2010 7:22 AM
    • Marked as answer by Ai-hua Qiu Tuesday, September 07, 2010 6:22 AM
    Monday, August 30, 2010 11:44 PM
    Moderator

All replies

  • > COUNT(ACT) AS TOT

    You are not doing anythig with TOT?

    Plain self insert should go without any issue.

    If you do some operation, like calculation, and insert,  that can have some issues.

    Plain self insert demo follows:

    -- SQL Server table self-insert demo
    USE tempdb;
    SELECT ProductNumber, ProductName=name, ListPrice 
    INTO ProdShort FROM AdventureWorks2008.Production.Product
    GO
    -- (504 row(s) affected)
    
    INSERT ProdShort SELECT * FROM ProdShort
    -- (504 row(s) affected)
    INSERT ProdShort SELECT * FROM ProdShort
    -- (1008 row(s) affected)
    INSERT ProdShort SELECT * FROM ProdShort
    -- (2016 row(s) affected)
    

    Kalman Toth, SQL Server & Business Intelligence Training; SQL 2008 GRAND SLAM
    • Proposed as answer by Atif-ullah Sheikh Tuesday, August 31, 2010 7:22 AM
    • Marked as answer by Ai-hua Qiu Tuesday, September 07, 2010 6:22 AM
    Monday, August 30, 2010 11:44 PM
    Moderator
  • shamen

    Please explain on what is the purpose?  What are  you traying to achive?


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Tuesday, August 31, 2010 6:47 AM
    Answerer