• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Returning exact field length in sql query

I am using sql to create a flat file. I have this line of sql

 case when LEFT([Last_Name_Applicant], 16) is NULL then  space(16)  else LEFT([Last_Name_Applicant], 16) end as  [NAME-L],

I want my query to return a length of 16 even if the value of the field is just 6
for example "Davies"

Query should return "Davies          "

Please assist.
0
Sirdots
Asked:
Sirdots
2 Solutions
 
Chris LuttrellSenior Database ArchitectCommented:
try :
CONVERT(CHAR(16), LEFT(Last_Name_Applicant, 16))
0
 
lluddenCommented:
Or SELECT LEFT([Last_Name_Applicant] + SPACE(16),16)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now