tia_kamakshi
asked on
Logic for generation code in C#
Hi,
I am working on C#, ASP.Net 1.2, and MSSQL 2000
In my database I have the code like C02, C03...C10, S01, S02, S05... etc. where first letter stands for the supplier name
Now, When I create the new code for supplier it should take the first letter from suppler name and the next 2 availabe digits
means if the max code availabe for supplier Cxyz is C20 then the next code generated for the supplier should be C21.
How to find the next available code and set the code to the supplier.
I require the logic for this
Thanks
I am working on C#, ASP.Net 1.2, and MSSQL 2000
In my database I have the code like C02, C03...C10, S01, S02, S05... etc. where first letter stands for the supplier name
Now, When I create the new code for supplier it should take the first letter from suppler name and the next 2 availabe digits
means if the max code availabe for supplier Cxyz is C20 then the next code generated for the supplier should be C21.
How to find the next available code and set the code to the supplier.
I require the logic for this
Thanks
Oops.. sorry, didn't read your question carefully.
In your case I think you have to
1. Query your database to get the max number (for that supplier)
2. Do increment
3. Add supplier's first letter to get new code.
In your case I think you have to
1. Query your database to get the max number (for that supplier)
2. Do increment
3. Add supplier's first letter to get new code.
ASKER
But how do I get the max number, If I can get the max number then it was easy. Since I ave the code like C01, C02... these are not int
Thanks
Thanks
you can do the following logic
you can improve the logic
the logic i am giving is for SQL Server 2000
Declare @SuppID Varchar(20)
Select @SuppID = Max(Supplier_ID) From Suppliers
Declare @IntSupplierID Int
Declare @temp Varchar(10)
Select @Temp = Substring(@SuppID, 2, len(@SuppID) - 1)
Select @IntSupplierID = Convert(Int, @temp)
Select @IntSupplierID = @IntSupplierID + 1
Print @IntSupplierID
If you want to make the integer of a particular length i.e. append zeros in fron of the number then you will have to use the string concatenation to make the string of a fixed size.
you can improve the logic
the logic i am giving is for SQL Server 2000
Declare @SuppID Varchar(20)
Select @SuppID = Max(Supplier_ID) From Suppliers
Declare @IntSupplierID Int
Declare @temp Varchar(10)
Select @Temp = Substring(@SuppID, 2, len(@SuppID) - 1)
Select @IntSupplierID = Convert(Int, @temp)
Select @IntSupplierID = @IntSupplierID + 1
Print @IntSupplierID
If you want to make the integer of a particular length i.e. append zeros in fron of the number then you will have to use the string concatenation to make the string of a fixed size.
Well, that's simple:
Select Max(supplierID)
From Supplier
Where SupplierID like 'C%';
After that... use the code above :P
Select Max(supplierID)
From Supplier
Where SupplierID like 'C%';
After that... use the code above :P
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
string newCode = customerCode.subString(0, 1);
int currentNumber = int.Parse(customerCode.sub
newNumber = currentNumber + 1;
newCode += newNumber.toString();