Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
mamta writes "I have a table in SQL server which is then exported as a flat file for mainframe process. I need to have one of the numeric field prefilled with zeros. PS the field length has to be 15 characters long. ANy help is appreciated."
SamC
White Water Yakist
3467 Posts
Posted - 2003-10-21 : 08:20:20
Select RIGHT('000000' + IsNull(CAST(MyIntCol as VARCHAR), 6), '')This will create a 6 digit integer with leading zeros.
mohdowais
Sheikh of Yak Knowledge
1456 Posts
Posted - 2003-10-21 : 08:21:28
Try SELECT RIGHT('000000000000000' + MyIntColumn) FROM TableNameOwaisedit: !Make it idiot proof and someone will make a better idiot
X002548
Not Just a Number
15586 Posts
Posted - 2003-10-21 : 10:50:34
Owais!
DECLARE @MyIntColumn intSELECT @MyIntColumn = 1SELECT RIGHT('000000000000000' + @MyIntColumn) -- Still needs the second parameterSELECT RIGHT('000000000000000' + @MyIntColumn, 15) -- Seems to be an implicit conversion to intSELECT RIGHT(REPLICATE('0',15)+CONVERT(varchar(15),@MyIntColumn),15)
Brett8-)
mohdowais
Sheikh of Yak Knowledge
1456 Posts
Posted - 2003-10-21 : 11:09:27
Do they have an icon for dumb yak?duh...not enough coffee today...been on the road, drove at least 100 miles today in crazy traffic!OwaisMake it idiot proof and someone will make a better idiot
Amethystium
Aged Yak Warrior
701 Posts
Posted - 2003-10-21 : 12:32:55
The only thing I dislike about this site is the YAK business. Could someone explain to me what this is all about. YAK SQL.... what the...?!__________________Make love not war!
graz
Chief SQLTeam Crack Dealer
4149 Posts
Posted - 2003-10-21 : 22:57:53
If that's the only thing you dislike we must be doing something right! Me? I'm getting less and less fond of the blue all over the site. Blue, blue blue.But ... back to the yak! Obviously you haven't fully considered the myriad of benefits associated with the yak -- commonly known as the Bison of Tibet. Maybe a quick perusal of the yak section on the site will help you "back the yak".http://www.sqlteam.com/FilterTopics.asp?TopicID=148After all, how many technical sites have an official mascot? Well, ok, barely semi-offical at best. I am always curious what people think when the occasional yak link pops into their search result. On the bright side if you were to search Google on "sql server and yak" we're first! It's good to be first.===============================================Creating tomorrow's legacy systems today.One crisis at a time.
mohdowais
Sheikh of Yak Knowledge
1456 Posts
Posted - 2003-10-22 : 02:44:30
Yikes...Graz! the last two links on our beloved yak page don't work!!OwaisMake it idiot proof and someone will make a better idiot