?
Solved

Returning exact field length in sql query

Posted on 2012-04-04
2
Medium Priority
?
308 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 1000 total points
ID: 37807851
try :
CONVERT(CHAR(16), LEFT(Last_Name_Applicant, 16))
0
 
LVL 18

Accepted Solution

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

777 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