Set length of fields in view

  • I am developing a view that will eventually be used as the source for a nightly extraction to a flat file. This flat file requires that each field uses certain columns, for example Field 1 uses columns 1 - 20, Field 2 uses 21-24, etc.

    I like to set up my view/query to make each field its appropriate length, need the right code to set the field length.

    Field 1 from the source table is 24, but in my view it needs to be 20.

  • robert_daniel (6/4/2009)


    I am developing a view that will eventually be used as the source for a nightly extraction to a flat file. This flat file requires that each field uses certain columns, for example Field 1 uses columns 1 - 20, Field 2 uses 21-24, etc.

    I like to set up my view/query to make each field its appropriate length, need the right code to set the field length.

    Field 1 from the source table is 24, but in my view it needs to be 20.

    Sounds like you can just cast these to the appropriate lengths, although from your example you will

    be truncating data.

    SELECT CAST(Field1 AS CHAR(20)) AS Field1

    ...

    FROM ...

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537
  • Hi,

    some more specification will help to better understand the problem.

    "Don't limit your challenges, challenge your limits"

  • Looks like CAST will do the trick - thanks!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply