September 7, 2011 at 11:36 am
I need to convert auto ID to a file name.
For example, file name's length will be 8 characters such as 00000123, 00000056, 01234568. Here, 123, 56 or 1234568 are come from auto ID.
How to code it?
September 7, 2011 at 12:28 pm
Something like
SELECT RIGHT(100000000 + ID, 8)
FROM YourTable
September 7, 2011 at 12:35 pm
here's an example of two different techniques that do the same thing:
/*ANewIDDiffID
0000012300000123
0000005600000056
0123456801234568
*/
With MySampleData (TheID)
AS
(SELECT 123 UNION ALL
SELECT 56 UNION ALL
SELECT 1234568 )
SELECT
REPLACE(STR(TheID,8),' ','0') As ANewID,
RIGHT('00000000' + convert(varchar,TheID),8) As DiffID
From MySampleData
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply