T-SQL: Number of characters
Posted on 2014-04-29
Below is a snippet of my T-SQL programming where I'm trying to very specifically tell SQL how many characters are to be accommodated by each field. For example, the "rectype" field is to be 15 characters long.
But, this programming does not seem to be set in logic. For example, the field "wotclocname" is to start at position 137. Yet, it starts at position 138. Somehow, I'm off one character.
What I'm trying to ask is this: "Is there a better way of telling SQL how many characters a field should be?".
Sure, I could reduce the number of one of the other fields by 1. But, I want to know how this logic is flawed.
CAST('140ERWOTCLOC' as CHAR(15)) as rectype,
CAST('16860' as CHAR(16)) as cocode,
CAST('' as CHAR(75)) as filler,
CAST('71912' as CHAR(5)) as tci_id,
CAST('100' as CHAR(25)) as wotclocnumber,
CAST(' Anodyne Medical Services Corp' as CHAR(50)) as wotclocname