Solved

SQL Server INsert question

Posted on 2010-09-24
8
194 Views
Last Modified: 2012-05-10
Truncate Table sysdba.MDMSACCOUNT_UPLOADSTAGING

SET IDENTITY_INSERT [sysdba].[MDMSACCOUNT_UPLOADSTAGING] ON
go
INSERT INTO [CAST].[sysdba].[MDMSACCOUNT_UPLOADSTAGING]
                  --(--MDMSACCOUNT_UPLOADID,
           (ACCOUNTID,ACCOUNT,SWIFT_BIC_CODE,AUDIT,INSERT_DATETIME,SENT_DATETIME)
SET IDENTITY_INSERT sysdba.MDMSACCOUNT_UPLOADSTAGING OFF


I am trying to insert into a table with Identity Column
SELECT
--(--MDMSACCOUNT_UPLOADID,
([ACCOUNTID],[ACCOUNT],[SWIFT_BIC_CODE],[AUDIT]
      ,CONVERT( varchar(10), INSERT_DATETIME,120) as [INSERT_DATETIME]
      ,[SENT_DATETIME])
FROM [CAST].[sysdba].[MDMSACCOUNT_UPLOAD]
WHERE     AUDIT IN ('A', 'U', 'Y') AND SENT_DATETIME IS NULL
0
Comment
Question by:olaayo
[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
  • 2
  • 2
  • +1
8 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33752141
you want to "copy" the ID value into the new table, right?
SET IDENTITY_INSERT [sysdba].[MDMSACCOUNT_UPLOADSTAGING] ON

INSERT INTO [CAST].[sysdba].[MDMSACCOUNT_UPLOADSTAGING]
  ( MDMSACCOUNT_UPLOADID
  , ACCOUNTID,ACCOUNT,SWIFT_BIC_CODE,AUDIT,INSERT_DATETIME,SENT_DATETIME
  )
SELECT MDMSACCOUNT_UPLOADID
  , [ACCOUNTID],[ACCOUNT],[SWIFT_BIC_CODE],[AUDIT]
  , CONVERT( varchar(10), INSERT_DATETIME,120) as [INSERT_DATETIME]
  , [SENT_DATETIME])
  FROM [CAST].[sysdba].[MDMSACCOUNT_UPLOAD]
 WHERE     AUDIT IN ('A', 'U', 'Y') 
   AND SENT_DATETIME IS NULL 

SET IDENTITY_INSERT sysdba.MDMSACCOUNT_UPLOADSTAGING OFF

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33752144
if that is not the problem, please clarify
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 33752158
Is below code is what you are trying to do?
Truncate Table sysdba.MDMSACCOUNT_UPLOADSTAGING

SET IDENTITY_INSERT [sysdba].[MDMSACCOUNT_UPLOADSTAGING] ON
GO
INSERT INTO [CAST].[sysdba].[MDMSACCOUNT_UPLOADSTAGING]
       (ACCOUNTID, ACCOUNT, SWIFT_BIC_CODE, AUDIT,
        INSERT_DATETIME, SENT_DATETIME)
SELECT  ACCOUNTID, ACCOUNT, SWIFT_BIC_CODE, AUDIT,
        CONVERT( varchar(10), INSERT_DATETIME,120) as [INSERT_DATETIME],
        [SENT_DATETIME]
FROM [CAST].[sysdba].[MDMSACCOUNT_UPLOAD]
WHERE     AUDIT IN ('A', 'U', 'Y') AND SENT_DATETIME IS NULL
GO
SET IDENTITY_INSERT sysdba.MDMSACCOUNT_UPLOADSTAGING OFF
GO

Open in new window

0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 

Author Comment

by:olaayo
ID: 33752405
I am trying to run  insert in to this table
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [sysdba].[MDMSACCOUNT_UPLOADSTAGING](
      [MDMSACCOUNT_UPLOAD_ID] [int] IDENTITY(1,1) NOT NULL,
      [MDMSACCOUNT_UPLOADID] [char](12) NULL,
      [ACCOUNTID] [char](12) NOT NULL,
      [ACCOUNT] [varchar](30) NOT NULL,
      [SWIFT_BIC_CODE] [varchar](11) NULL,
      [AUDIT] [char](1) NOT NULL,
      [INSERT_DATETIME] [datetime] NOT NULL,
      [SENT_DATETIME] [datetime] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
0
 
LVL 9

Expert Comment

by:sureshbabukrish
ID: 33752458
did not understand your question
0
 

Author Comment

by:olaayo
ID: 33752505
Truncate Table sysdba.MDMSACCOUNT_UPLOADSTAGING

SET IDENTITY_INSERT [sysdba].[MDMSACCOUNT_UPLOADSTAGING] ON
go
INSERT INTO [CAST].[sysdba].[MDMSACCOUNT_UPLOADSTAGING]
                  --(--MDMSACCOUNT_UPLOADID,
           (ACCOUNTID,ACCOUNT,SWIFT_BIC_CODE,AUDIT,INSERT_DATETIME,SENT_DATETIME)
SET IDENTITY_INSERT sysdba.MDMSACCOUNT_UPLOADSTAGING OFF


I am trying to insert into a table with Identity Column
SELECT
--(--MDMSACCOUNT_UPLOADID,
([ACCOUNTID],[ACCOUNT],[SWIFT_BIC_CODE],[AUDIT]
      ,CONVERT( varchar(10), INSERT_DATETIME,120) as [INSERT_DATETIME]
      ,[SENT_DATETIME])
FROM [CAST].[sysdba].[MDMSACCOUNT_UPLOAD]
WHERE     AUDIT IN ('A', 'U', 'Y') AND SENT_DATETIME IS NULL


I am trying to run  insert in to this table using the query above
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [sysdba].[MDMSACCOUNT_UPLOADSTAGING](
      [MDMSACCOUNT_UPLOAD_ID] [int] IDENTITY(1,1) NOT NULL,
      [MDMSACCOUNT_UPLOADID] [char](12) NULL,
      [ACCOUNTID] [char](12) NOT NULL,
      [ACCOUNT] [varchar](30) NOT NULL,
      [SWIFT_BIC_CODE] [varchar](11) NULL,
      [AUDIT] [char](1) NOT NULL,
      [INSERT_DATETIME] [datetime] NOT NULL,
      [SENT_DATETIME] [datetime] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
0
 
LVL 9

Expert Comment

by:sureshbabukrish
ID: 33752640
what error message are you getting?
0
 

Author Comment

by:olaayo
ID: 37783457
Perfect solution Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

710 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