Solved

SQL Server INsert question

Posted on 2010-09-24
8
188 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 142

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 142

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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Designer 19 42
SQL Server - Set Value of Multiple Fields in One Query 10 25
SQL - Copy data from one database to another 6 19
replace \ by - in select 4 21
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

777 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