Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server INsert question

Posted on 2010-09-24
8
Medium Priority
?
202 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 2000 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 2000 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

718 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