Hello gnixon14,
this is how it should be done in sql way
insert into ....
select RIGHT( replicate('0',12) + DWFolderUserKey , 12 ) ,
GOD BLESS,
Aneesh R.
Main Topics
Browse All TopicsGood morning experts,
I have a problem that has been driving me nuts for 2 days. I figure it's time to ask for help.
This is my sql insert string in a vb.net app
SQLFString = "Insert Into Foldering (FolderUserKey, FolderUserMediaType, UserMediaType, MediaId) VALUES (" & DWFolderUserKey & ",'" & DWFolderUserMediaType & " ','" & DWUserMediaType & "','" & DWMediaID & "')"
I've tried every way that I know how to pad zero's to the left of DWFolderUserKey. And it works up to the insert statement. Then SQL strips them. FolderUSerKey is a varchar field. I need to have a total of 12 characters.
Any help would be greatly appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If DWFolderUserKey is a string variable, and it has been left padded with 0s, and you are putting it into a varchar field then all you need to alter in your current statement is add single quotes round that variable as you have round the others
SQLFString = "Insert Into Foldering (FolderUserKey, FolderUserMediaType, UserMediaType, MediaId) VALUES ('" & DWFolderUserKey & "','" & DWFolderUserMediaType & " ','" & DWUserMediaType & "','" & DWMediaID & "')"
The issue at the moment is that VB.NET - not SQL - is stripping leading zeros because, without the quotes, it is treating the variable as a number.
Roger
Doh! I did it again. Pasted the wrong version
I meant to say
That last paragraph is is a bit misleading. It should say something like
The issue at the moment is that the statement that VB.NET is passing to SQL is stripping leading zeros because, without the quotes, it is treating the variable as a number.
Roger
Business Accounts
Answer for Membership
by: gattyttoPosted on 2008-05-30 at 08:27:26ID: 21678661
if you are going to store FolderUSerKey variable as a String into the database..
First, check that FolderUSerKey is a String, then check the length of that string, if it's less than 12, then add the ceros at the left into the variable and then execute the sql query using the already modified variable.. is that what you need? if not, please give a bit more details on what you need.
teb.