logo
down
shadow

select from one table and insert into another


select from one table and insert into another

By : chiragbodana
Date : October 16 2020, 11:12 PM
help you fix your problem I've got two tables. , Have you tried
code :


Share : facebook icon twitter icon
SELECT takes 100ms; CREATE table as select - or - INSERT into select take 15mins

SELECT takes 100ms; CREATE table as select - or - INSERT into select take 15mins


By : Balbir
Date : March 29 2020, 07:55 AM
seems to work fine Ok, I found it.
It's the alternate-key on UDA_NAME for table USER_DEF_ATTRIBUTES.
Insert Query to insert multiple rows in a table via select and output clause. SQL Server 2008

Insert Query to insert multiple rows in a table via select and output clause. SQL Server 2008


By : Vivek Kumar
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a created a stored procedure (please ignore syntax errors) , Change your procedure like below,and try again.
code :
ALTER PROCEDURE usp_newServerDetails(@appid int, @envid int,@serType varchar(20),@servName varchar(20))
    AS
BEGIN
  BEGIN TRY

   DECLARE @Output TABLE (ID int,TableName VARCHAR(50),cmKey VARCHAR(50)) --table variable for keeping Inserted ID's

        BEGIN TRAN


         IF EXISTS ( SELECT 1 FROM configpthmaster cm  WHERE cm.appid = @appid ) 
                        AND  ( SELECT 1 FROM configkeydetails ck  WHERE ck.appid = @appid ) --add a conditon to satisfy the valid insertions

         BEGIN

            INSERT INTO server_detials(envid,servertype,servername)
                OUTPUT inserted.serverid,'server_detials',NULL INTO @Output(ID,TableName,cmKey )
            VALUES(@envid ,@serType ,@servName)

            INSERT INTO configdetails(serverid,servertype,configpath,configtype)
                OUTPUT inserted.configid,'configdetails',cm.Key INTO @Output(ID,TableName,cmKey )
            SELECT t.ID,cm.servertype,cm.configpath,cm.configtype 
            FROM configpthmaster cm 
              CROSS APPLY (SELECT ID FROM @Output WHERE TableName='server_detials')t
            WHERE cm.appid = @appid

            INSERT INTO configkeydetails(configId,keyname)
            SELECT ID,cmKey FROM @Output 
            WHERE TableName='configdetails'

        END

       COMMIT TRAN
  END TRY

    BEGIN CATCH

        IF @@TRANCOUNT > 0 
        ROLLBACK 

    END CATCH

END
Insert data from a table to a temporary table, and then select from the temp table specific rows

Insert data from a table to a temporary table, and then select from the temp table specific rows


By : Karla
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I'm trying to get rows from an existing table (by columns: p_id, e_id, ts, data1, data2, data3) to a temporary table (indexed by p_id, e_id, ts), and then selecting specific rows from that temporary table as a result. Then terminate the temporary table (because that's what CREATE TEMPORARY does, right?)
code :
CREATE TEMPORARY TABLE IF NOT EXISTS 
  pet_temp ( INDEX(p_id, e_id, ts) )  
AS (
  SELECT p_id, e_id, ts, data1, data2, data3
  FROM processes_history
  WHERE e_id=4362 AND ts BETWEEN '2017-03-01' AND '2017-04-01'
) ;
SELECT p_id, e_id, ts, data1, data2, data3 FROM pet_temp WHERE p_id IN (11,22,33,44,55,66,77,88,99);

Drop temporary table if exists pet_temp ;
Insert result of select statement into a SQL Server 2016 table or temp table to then insert or select into

Insert result of select statement into a SQL Server 2016 table or temp table to then insert or select into


By : Manikandan Muthuraj
Date : March 29 2020, 07:55 AM
will help you Literally the first time I have posted, so please excuse me if I have done it incorrectly. , To insert into a table from a select result try this way:
code :
DECLARE @json nvarchar(max)

SET @json = N'{
  "response": [
    {
      "application": {
        "info": {
          "dat_id": "010.2018.00036494.001",
          "development_type": "Residential - Single new dwelling",
          "application_type": "DA",
          "last_modified_date": "2018-12-03T11:35:24+11:00",
          "description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
          "authority": {
            "ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
            "name": "AlburyCity"
          },
          "lodgement_date": "2018-10-26T00:00:00+11:00",
                  )
[…..]


select * into results_from_query from OPENJSON(@json,'$.response')
with
(
[dat_id] varchar(200) '$.application.info.dat_id',
[development_type] varchar(200) '$.application.info.development_type',
[last_modified_date] varchar(200) '$.application.info.last_modified_date',
[description] varchar(300) '$.application.info.description',
[ref] varchar(200) '$.application.info.authority.ref',
[name] varchar(200) '$.application.info.authority.name'
)
ORA-08103 Using global temporary table DML(insert, update, select) inside a procedure, select cursor to temp-table shows

ORA-08103 Using global temporary table DML(insert, update, select) inside a procedure, select cursor to temp-table shows


By : JustJJ
Date : March 29 2020, 07:55 AM
Any of those help Temporary Tables in SQL Server are different from Global Temporary Tables in Oracle. Specifically, Global Temporary Table are permanent data structures it's just the data which is temporary. Data in a GTT is restricted to the session which inserted it, and will be wiped at the end of the transaction or session, depending on how the table is defined.
The other thing about your procedure is that it passes an opened ref cursor to the calling program. A cursor is not a data set, it is a pointer to a query: the calling program then fetches the data, which means it executes the query and processes its result set. The problem is, immediately after opening the query your procedure executes EXECUTE IMMEDIATE 'TRUNCATE TABLE REM_ORDENSECCIONESP';. Consequently, when the calling program attempts to fetch records form the cursor the cupboard is bare.
Related Posts Related Posts :
  • Shipping dates job
  • Blank Space in every row of table SQL
  • How to select only incremental records in BIG QUERY
  • SQL Server: check if specific string exists in column
  • SQL Server : remove trailing 0's after decimal point. nvarchar datatype
  • How to query indexed values in XML column using SQL Server
  • Make a DB2 Schema public so that all tables are readable to PUBLIC
  • oracle sql - using double ampersand (&&) and double dot (..)
  • Cognos CAST within a CASE
  • Store exponent in postgres table
  • INSERT INTO Too few parameters
  • How to make massive selection SAP ABAP
  • OLEDB Connection has no refresh date
  • Forward declaration in package
  • Find MIN and MAX date on a discontinuous period of time YYYYMM00
  • SQL query to turn change log into intervals
  • LEFT JOIN ON most recent date in Google BigQuery
  • How to select oldest record from sql
  • Removing users accounts with a zero order value inside wordpress multisite database
  • RDBMS: Calculate and print the return date, return month, and return year
  • SQL : list differences between rows (showed in columns)
  • SQL SERVER -- YEAR
  • Change Primary Key
  • How do you PIVOT on a Bit datatype in SQL Server?
  • Shuold I use not exists or join statement to filter out NULLs?
  • How do i call a shell app from SQL storedprocedure?
  • parameterized query in ms access 2003 using vba
  • Web Service or Windows Service or SQL CLR Integration?
  • How can I store the result of a SQL query in a CSV file using Squirrel?
  • Looking for a way to limit SQL results 3 results per a specific column
  • Why isn't SSMS smart when it comes to adding columns?
  • Advice on Change Tracking in Sql Server 2008
  • How do I convert this INNER JOIN query from SQL Server to MySQL?
  • How to get script of SQL Server data?
  • mysql select query help -- ORDER BY
  • How to set a local variable to the result of sql query in a batch file?
  • retrieving same column twice from a table
  • SQL update records compared to records from another table
  • SQL - Mixing ANDs and ORs
  • Using list alias in WHERE or GROUP BY clause
  • Year to date per month
  • SQL natural join POSTGRES
  • how to insert an image into a database using WPF
  • how to create tables using sql schemas
  • Replacing cube with rollup in Oracle SQL
  • Using rank to select top 10 tuples in Oracle SQL
  • TSQL: query with optional join
  • Problem with UTL_FILE.FCOPY in a trigger
  • Revoking permission in oracle
  • Inserting one record at a time to multiple tables from a table
  • Deleting top rows only. SQL Server
  • SQL Server FTS: Ranking is a bit strange
  • In MySQL, how to copy the content of one table to another table within the same database?
  • spring batch insert using hibernateTemplate, JdbcTemplate
  • How to delete a record when two tables have foreign key referenced to each other?
  • SELECT with conditions for preferential source
  • SELECT question
  • echo out from the UNION sql?
  • Order database query results along a curve
  • Howto query for random rows?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org