Solved

Returning exact field length in sql query

Posted on 2012-04-04
2
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

726 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