Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:34:32+00:00 2026-06-09T21:34:32+00:00

Possible Duplicate: bulk insert a date in YYYYMM format to date field in MS

  • 0

Possible Duplicate:
bulk insert a date in YYYYMM format to date field in MS SQL table

I am using SQL Server 2012 Express.

I have a problem with using BULK INSERT from file that contains dates in format YYYYMMDD (can’t change the format, it’s an output from different software). I use a format file, as I have an identity column that should be skipped when inserting values. Table structure and BULK INSERT command are here:

CREATE TABLE [dbo].[daily](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[ticker] [varchar](15) NOT NULL,
[ddate] [date] NOT NULL,
[dopen] [decimal](16, 8) NOT NULL,
[dhigh] [decimal](16, 8) NOT NULL,
[dlow] [decimal](16, 8) NOT NULL,
[dclose] [decimal](16, 8) NOT NULL,
[dvol] [int] NOT NULL,
[dopenint] [int] NOT NULL
);


BULK INSERT daily
FROM 'C:\IBM.TXT'
WITH (
FORMATFILE = 'C:\dailyformat.xml',
TABLOCK,
FIRSTROW = 2);

Tab-delimited data file (IBM.TXT) is here:

Symbol  Date     Open    High    Low     Close   Total Volume    Total Open Interest
IBM 19620102     2.57000000  2.57000000  2.54000000  2.54000000    11704           0
IBM 19620103     2.54000000  2.56000000  2.54000000  2.56000000     8778           0
IBM 19620104     2.56000000  2.56000000  2.54000000  2.54000000     7878           0
IBM 19620105     2.53000000  2.53000000  2.48000000  2.49000000    11029           0
IBM 19620108     2.49000000  2.49000000  2.42000000  2.44000000    16431           0
IBM 19620109     2.45000000  2.50000000  2.45000000  2.47000000    14855           0

Format file (dailyformat.xml), generated by bcp, is here:

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <RECORD>
  <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="15"/>
  <FIELD ID="2" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="11"/>
  <FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="41"/>
  <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="41"/>
  <FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="41"/>
  <FIELD ID="6" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="41"/>
  <FIELD ID="7" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="12"/>
  <FIELD ID="8" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="12"/>
 </RECORD>
 <ROW>
  <COLUMN SOURCE="1" NAME="ticker" xsi:type="SQLVARYCHAR"/>
  <COLUMN SOURCE="2" NAME="ddate" xsi:type="SQLDATE"/>
  <COLUMN SOURCE="3" NAME="dopen" xsi:type="SQLDECIMAL" PRECISION="16" SCALE="8"/>
  <COLUMN SOURCE="4" NAME="dhigh" xsi:type="SQLDECIMAL" PRECISION="16" SCALE="8"/>
  <COLUMN SOURCE="5" NAME="dlow" xsi:type="SQLDECIMAL" PRECISION="16" SCALE="8"/>
  <COLUMN SOURCE="6" NAME="dclose" xsi:type="SQLDECIMAL" PRECISION="16" SCALE="8"/>
  <COLUMN SOURCE="7" NAME="dvol" xsi:type="SQLINT"/>
  <COLUMN SOURCE="8" NAME="dopenint" xsi:type="SQLINT"/>
 </ROW>
</BCPFORMAT>

I get the following error:

Msg 206, Level 16, State 2, Line 1
Operand type clash: numeric is incompatible with date.

Please help to fix it without inserting date as number to a temporary table and then converting it to date by selecting it into other table. There should be some fix to my code.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:34:33+00:00Added an answer on June 9, 2026 at 9:34 pm

    Problem solved. I used

    INSERT INTO daily 
    SELECT a.* FROM OPENROWSET(
    BULK 'C:\IBM.TXT',
    FORMATFILE = 'C:\dailyformat.xml',
    FIRSTROW = 2
    ) as a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Find the smallest unused number in SQL Server I have this table
Possible Duplicate: Bulk Insert of hundreds of millions of records So I was just
Possible Duplicates: SQL Server - bulk delete (truncate vs delete) What’s the difference between
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Is there a way to create a SQL Server function to “join”
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.