Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating fields with length less than 4 1

Status
Not open for further replies.

anikanchan

Programmer
Jul 18, 2005
11
US
Hello guys,

I need to update table where lenth of the characters is less than 5 for a column and I need to add a leading zero to it. Can someone help me out with this please?

Actually, I am copying data into a table from Excel file and it leaves the leading zero. If I can copy it in such a way that it retains the leading zero than it would do too. Any comments/help is appreciated.

Thanks,

Anikanchan
 
Pleas show sample data, and what you are getting and what you want to get.
 
Thanks jbenson001,

Here is the sample data:


Company Dept # Dept Name
010 01110 Office of the President
010 03160 Executive Services
010 01240 Dir Internal Audit
010 01250 Corporate Audit & Advisory Svc
010 01260 Systems Audit
010 01270 Cust Audit Services
010 01280 Quality Assessment
010 01320 Par Plan Audit Svcs
010 01330 Business Risk Svcs
010 01510 VP and Gen Auditor
010 37150 Internal Control Compliance
010 01220 Board Relations



This is the format from Excel...once I copy it into the SQL Server table, it drops the leading zero for the dept#.

Anikanchan
 
Try this:
Code:
update Table
set    dept# = '0' + dept# 
where  len(dept#) < 5

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top