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 9170331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:00:13+00:00 2026-06-17T16:00:13+00:00

I’m trying to load some data from a fixed width text file into a

  • 0

I’m trying to load some data from a fixed width text file into a view, with the insertion intercepted by an instead-of trigger.

The debug select that’s supposed to output the values from INSERTED in the trigger doesn’t get triggered, so I suspect the point of failure is the bulk insert itself.

Here are the details:
Here’s what I’m using:

The initiating bulk insert command looks like this:

BULK INSERT Staging.vViewSolelyForInsertion
FROM 'X:\path\to\datafile.txt'
WITH
(
    FORMATFILE='X:\path\to\formatfile.xml',
    FIRE_TRIGGERS,
    ERRORFILE='X:\path\to\Error.log'
)

CREATE command used for Staging.vViewSolelyForInsertion:

CREATE VIEW Staging.vViewSolelyForInsertion
AS
SELECT
    CONVERT(NVARCHAR(4), NULL, 0) AS Door,
    CONVERT(NVARCHAR(9), NULL, 0) AS Chair,
    CONVERT(NVARCHAR(24), NULL, 0) AS Office,
    CONVERT(NVARCHAR(10), NULL, 0) AS Telephone,
    CONVERT(NVARCHAR(4), NULL, 0) AS Cup,
    CONVERT(NVARCHAR(1), NULL, 0) AS Headphones,
    CONVERT(NVARCHAR(20), NULL, 0) AS Mouse,
    CONVERT(NVARCHAR(12), NULL, 0) AS Keyboard

CREATE command used to create the trigger

CREATE TRIGGER Staging.ON_INSERT_Staging_vViewSolelyForInsertion
ON Staging.vRefViewSolelyForInsertion
BEGIN

    SELECT * FROM INSERTED -- debug, the error message appears before this point.

    /*
        This table exists to generate the InternalId.
    */  
    DECLARE @tbl TABLE
    (
        InternalId UNIQUEIDENTFIER NOT NULL DEFAULT NEWID(),
        Door,
        Chair,
        Office,
        Telephone,
        Cup,
        Headphones,
        Mouse,
        Keyboard
    )

    INSERT INTO @tbl
    (
        Door,
        Chair,
        Office,
        Telephone,
        Cup,
        Headphones,
        Mouse,
        Keyboard
    )
    SELECT
        i.Door,
        i.Chair,
        i.Office,
        i.Telephone,
        i.Cup,
        i.Headphones,
        i.Mouse,
        i.Keyboard
    FROM INSERTED i

    SELECT * FROM @tbl -- 2nd debug

    INSERT INTO Staging.ActualTable
    (
        InternalId,
        Door,
        Chair,
        Office,
        Telephone,
        Cup,
        Headphones,
        Mouse,
        Keyboard
    )
    SELECT
        -- Lots of processing goes on here. 
        t.InternalId,
        ProcessDoor(t.Door, t.InternalId),
        ProcessChair(t.Chair, t.InternalId),
        ProcessOffice(t.Office, t.InternalId),
        ProcessTelephone(t.Telephone, t.InternalId),
        ProcessCup(t.Cup, t.InternalId),
        ProcessHeadphones(t.Headphones, t.InternalId),
        ProcessMouse(t.Mouse, t.InternalId),
        ProcessKeyboard(t.Keyboard, t.InternalID)
    FROM @tbl t

    DELETE FROM @tbl

END

This is the format file I’m using

<?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="NCharFixed"   LENGTH="4"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="2"     xsi:type="NCharFixed"   LENGTH="9"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="3"     xsi:type="NCharFixed"   LENGTH="24" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="4"     xsi:type="NCharFixed"   LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="5"     xsi:type="NCharFixed"   LENGTH="4"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="6"     xsi:type="NCharFixed"   LENGTH="4"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="7"     xsi:type="NCharFixed"   LENGTH="1"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="8"     xsi:type="NCharFixed"   LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="9"     xsi:type="NCharFixed"   LENGTH="10" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="10"    xsi:type="NCharFixed"   LENGTH="4"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="11"    xsi:type="NCharFixed"   LENGTH="9"  COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="12"    xsi:type="NCharFixed"   LENGTH="20" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="13"    xsi:type="NCharFixed"   LENGTH="12" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  <FIELD ID="14"    xsi:type="CharTerm"     TERMINATOR="\r\n" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
 </RECORD>
 <ROW>
  <COLUMN SOURCE="1"    NAME="Door"         LENGTH="4"      xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="2"    NAME="Chair"        LENGTH="9"      xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="3"    NAME="Office"       LENGTH="24"     xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="4"    NAME="Telephone"    LENGTH="10"     xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="5"    NAME="Cup"          LENGTH="4"      xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="7"    NAME="Headphones"   LENGTH="1"      xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="12"   NAME="Mouse"        LENGTH="20"     xsi:type="SQLNVARCHAR"/>
  <COLUMN SOURCE="13"   NAME="Keyboard"     LENGTH="12"     xsi:type="SQLNVARCHAR"/>
 </ROW>
</BCPFORMAT>

The data file consists of \r\n terminated lines, no separators between data fields and is saved in unicode. Each line is 138 characters long, plus the \r\n at the end of the line.

The error I get is the following:

Bulk load data conversion error (truncation) for row 1, column 2 (Chair).

The field lengths from the ImportFile.xml are the same as the column lengths in the ImportFile.xml are the same as the nvarchar lenghts in the Staging.vViewSolelyForInsertion.
As mentioned above (I know it’s a long time ago), the first debug statement in the trigger doesn’t get executed, leading me to think that it’s the BULK INSERT that fails.

Thanks in advance!

  • 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-17T16:00:14+00:00Added an answer on June 17, 2026 at 4:00 pm

    All this work for nothing. setting xsi:type to CharFixed instead of NCharFixed solved that problem, even though I’m using Unicode. Now I’m dealing with weird characters in my data (that show up as normal text in the input file).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.