Solved

Returning exact field length in sql query

Posted on 2012-04-04
2
296 Views
Last Modified: 2012-04-04
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
Comment
Question by:Sirdots
2 Comments
 
LVL 26

Assisted Solution

by:Chris Luttrell
Chris Luttrell earned 250 total points
ID: 37807851
try :
CONVERT(CHAR(16), LEFT(Last_Name_Applicant, 16))
0
 
LVL 18

Accepted Solution

by:
lludden earned 250 total points
ID: 37807882
Or SELECT LEFT([Last_Name_Applicant] + SPACE(16),16)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question