coder
coder

Reputation: 13250

Generate sequence of numbers prefix with an alphabet

I would like to generate a sequence of numbers as "A0000"(ie.. an alphabet followed by 4numbers not randomly generated numbers).

I have gone through this article which is done with Sql Server similarly how can I achieve it in VB.Net.

Here is the code for SQL Server:

create function CustomerNumber (@id int) 
returns char(5) 
as 
begin 
return 'C' + right('0000' + convert(varchar(10), @id), 4) 
end

Any suggestions are welcome.

Upvotes: 2

Views: 1673

Answers (2)

SysDragon
SysDragon

Reputation: 9888

The same function in VB.NET:

Function CustomerNumber(id As Integer) As String
    return "C" & id.ToString("0000")
End Function

Upvotes: 4

Tim Schmelter
Tim Schmelter

Reputation: 460098

This should do the same:

"C" & id.ToString("d4")

Demo

Upvotes: 2

Related Questions