I need help padding a column with a leading 0

Posted on 2013-10-10
Medium Priority
Last Modified: 2013-10-10
Hi Experts,
I need to create a query that will return a list of disctint Social Security Numbers from my Students table.  The problem I have is that some of the Social Security Numbers in my SSN column are only 8 characters long.  How can I add a leading 0 to socials that are only 8 characters long?

Thanks in advance,
Question by:mainrotor
  • 3
LVL 21

Assisted Solution

netcmh earned 1000 total points
ID: 39563275
right('00000000' + SSNID, 8)
LVL 75

Accepted Solution

Aneesh Retnakaran earned 1000 total points
ID: 39563278
If you want to update the table use this
update yourTable
set ssn =RIGHT ( '000000000'+SSN, 9 )
WHERE len (SSN) < 9

or select  uery like this

select RIGHT ( '000000000'+SSN, 9 ) as ssn
LVL 21

Expert Comment

ID: 39563289
my bad, it's 9 you're looking for.
LVL 21

Expert Comment

ID: 39563433
Very unexpected that you would send some points my way. But, I appreciate it.

Thanks for the grade & good luck.

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

597 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