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.
| Author |
Topic |
|
j4ydh
Starting Member
18 Posts |
Posted - 2010-07-29 : 04:32:41
|
| HiI am trying to create a select statement that takes the auto increment (ID field as int primary key) and is formated for display as a number with leading zeros and appending string info.So increments of 100:100200300 etc..need to be displayed as follows:a_000000000100.jpga_000000000200.jpga_000000000300.jpg.... a_000000001400.jpg etc..I am working on sql server management studio (2008) and everything is erroring and my eyes are starting to get bloodshot!Any help would be appreciatedJ |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-07-29 : 04:50:56
|
| Hello,You can try this:SELECT 'a_'+replicate('0',12-datalength(cast(<your_field_name> as varchar(12))))+ cast(<your_field_name> as varchar(12))+'.jpg'FROM <your_table_name>;Best regards,Devart Team |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-29 : 04:52:12
|
select'a_' + right('000000000000' + convert(varchar(12),ID),12) + '.jpg'from your_table No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
j4ydh
Starting Member
18 Posts |
Posted - 2010-07-29 : 05:11:46
|
| Hi, I was hoping that I had made a school boy error, but unfortunately I wasn't even close!Thank you Devart and webfred... spot onCheersJ |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-07-29 : 05:19:10
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|