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

  • Home
  • SEARCH
  • 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 6715469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:37:05+00:00 2026-05-26T08:37:05+00:00

I am creating a Ragged right (fixed) format file using a SQL to specify

  • 0

I am creating a “Ragged right” (fixed) format file using a SQL to specify the data to extract.

SELECT 
    'D'                                                             AS DTL_REC_TYP
    ,CAST(CONVERT(VARCHAR, dbo.GetCycleDate(), 120) AS CHAR(10))    AS DTL_FILE_GL_DT
    ,CAST(CONVERT(VARCHAR, GETDATE(), 120) AS CHAR(19))             AS DTL_FILE_CREATE_DT
    ,LEGAL_ENTTY_CD                                                 AS DTL_LEGAL_ENTITY
    ,CLIENT_ID                                                      AS DTL_CLIENT_ID
    ,ACCT_NUM                                                       AS DTL_ACCT_NUM
    ,BEN_OPT_CD                                                     AS DTL_BEN_OPT_CD
FROM
    MyTable 

Client_ID is an INT column in the database.

Q: How do I get the value to be right justified within the column?

I was considering changing my SQL to do this, but this seems ugly:

,RIGHT('000000000' + CAST(CLIENT_ID As varchar(9)),9)           AS DTL_CLIENT_ID

or

,RIGHT('         ' + CAST(CLIENT_ID As varchar(9)),9)           AS DTL_CLIENT_ID

Is there a better way to do it in SSIS instead of T-SQL. If not, is there a slightly better way in T-SQL? It seems to me that the format of the fixed flat file should or at least could be be soley defined in SSIS and that the SQL.

enter image description here

  • 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-05-26T08:37:06+00:00Added an answer on May 26, 2026 at 8:37 am

    Doing the formatting in SQL is ugly, but it does work.

    I prefer doing the formatting in a Script Component of a Data Flow Task, mainly because String.Format is so much more powerful than anything in T-SQL. In this case, the script would go between the DB data source of your choice and the flat file destination.

    enter image description here

    You’d change the query to something like this:

    SELECT 
        'D'                 AS DTL_REC_TYP
        ,dbo.GetCycleDate() AS FILE_GL_DT
        ,GETDATE()          AS FILE_CREATE_DT
        ,LEGAL_ENTTY_CD     AS DTL_LEGAL_ENTITY
        ,CLIENT_ID
        ,ACCT_NUM           AS DTL_ACCT_NUM
        ,BEN_OPT_CD         AS DTL_BEN_OPT_CD
    FROM
        MyTable 
    

    where you’re no longer trying to convert the numerics in the SQL. All the columns from your query would become input columns to the script component. For every column you want to format, add an output column to the script component with the data type of DT_WSTR and the appropriate width. In the script component itself, you just have to add code to the ProcessInputRow event:

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Row.DTL_CLIENT_ID = String.Format("{0:000000000}", Row.CLIENT_ID);
        // Do similar formatting for dates, money, whatever
    }
    

    Then your flat file destination just consumes the string output columns.

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

Sidebar

Related Questions

Creating My Windows Form Application and using ADO.Net as Data Access layer and SQL
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating a zip file using Send To -> Compressed folder excludes .hg folder on
When creating zip archive using python ZipFile, how can i set file mime types?
Creating a simple public/private keypair, such as through ssh-keygen does not create a file
Creating a document fragment using plain Javascript is dead simple: var docFragment = document.createDocumentFragment();
Creating a website using simple html(not html5) and css but got stock in mouseover
Creating a site in with FrogCMS and using alot of jquery to create an
creating a filter for a select menu and having a few problems! the first
Creating a simple UI using MS Access, hoping to do minimal actual coding (actually

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.