Solved

SQL Server INsert question

Posted on 2010-09-24
8
179 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now