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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Max Number with String Constraints

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-04-13 : 14:42:20
Ex: MaxNo=10
Digits=8
Then I need to Return The Number as 00000010

Like the same for any other maxno. If the Max no is 8 digit number then it will return the same 8 digit number.

How to built the above scenario in Sql Query. Please help me in this..

Regards,
Kalaiselvan R
Love Yourself First....

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-04-13 : 14:45:41
You should be doing this in the presentation layer...


but in SQL:


right(replicate('0',8)+convert(varchar,ManNo),8)

or generically

right(replicate('0',@digits)+convert(varchar,ManNo),@digits)



Corey

I Has Returned!!
Go to Top of Page

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2011-04-13 : 18:18:40
Thank You,
Its working fine and Issue is Fixed.

Regards,
Kalaiselvan R
Love Yourself First....
Go to Top of Page
   

- Advertisement -