Creating a custom registration number...

8 views
Skip to first unread message

nu1silva

unread,
Nov 17, 2009, 5:36:25 AM11/17/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hi all,

im developing a Student Management software and im just going through
the registration of a student.

i need to assign the registration number --> T(year)-(# of
registration for the year) so it'll be like
T09-001 or T09-089 or T09-243 an so on....

i get the input of the year and can count the number from the
database.

how can i get the registration number?

the sample o the Student Database...

CREATE TABLE Student_Details
(
Student_ID varchar(10) NOT NULL UNIQUE, -- example ( T09-001 )
Fname varchar(255),
Lname varchar(255),
Full_Name varchar(255), --
Address varchar(255),
DOB datetime,
ContactNO varchar(15),
email varchar(25),
additional_detail varchar(255),
Course_ID varchar(10),
Dateof_Admission datetime,
--Dateof_Graduation datetime,
PRIMARY KEY(Student_ID)
)


help!!! :(

Nuwan Silva

unread,
Nov 17, 2009, 8:39:36 PM11/17/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
yes i figured that thing i just want to know how i will be able to do that?

2009/11/17 nu1silva <nu1s...@gmail.com>



--
Thank You,
Best Regards,

Nuwan S. Silva
170, St. Anthony's Road,
Moratumulla, Moratuwa,
Sri Lanka.
Mobile  : +94 779 804 543
email    : nu1s...@gmail.com

Raghupathi Kamuni

unread,
Nov 18, 2009, 1:39:34 AM11/18/09
to dotnetde...@googlegroups.com
May be you have to maintain the Registration numbers in another table say....

CREATE

TABLE [dbo].[Registration](
[Year] [int] NOT NULL,
[RegistrationNumber] [int] NOT NULL
)

Based on the year, you have to autoincrement RegistrationNumber.

While inserting Student_Details generate the Student_ID from RegistrationNumber

Hope that helps !
 

B☼gus Excepti☼n

unread,
Nov 18, 2009, 8:35:30 AM11/18/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
And perhaps a SP to put them together when inserting?

Nuwan Silva

unread,
Nov 18, 2009, 5:06:55 AM11/18/09
to dotnetde...@googlegroups.com
yeah that might be a good idea.

but,
You could always use String.Format("T:{0}-{1:3}",Date.Now.Year.ToString
().Substring(2,2)
, SomeSQLRowcountFunction(student_details) )

this i what i wanted maybe i can work with something like this.

thanks guys :) sry if you couldn't understand what i wanted anyway i got a clue how to do it thanks :)

2009/11/18 Raghupathi Kamuni <raghu...@gmail.com>

nu1silva

unread,
Nov 18, 2009, 8:36:32 AM11/18/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
ok here we go again.... :(

asked this before an got some great answers but i'm still not able to
get it right :(

first of all,
im doin the project on Visual Studio 2005 C#.NET and using MSSQL
2005.

the objective is to register a student and save data on the DB.

what i want to do is create a custom Registration number or the
students that register for a course
examples,
T(year)-(student number)
so itll be like >>> T09-0118, T09-0001, T09-1234


how to get the input>>

T >> we must ad that
09 >> should get from date
- >> we add
0001 >> (where can i get that???)

and it would be great if i can create the Registration Number before i
insert it to the database.

im still learning and would appreciate the help :)
Thanks

Cerebrus

unread,
Nov 18, 2009, 11:12:16 AM11/18/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Possibly something like :

---
SELECT MAX(SUBSTRING(Student_ID, 5, 4))
FROM Student_Details
WHERE SUBSTRING(Student_ID, 2, 2) = @TwoDigitYear
---

Example param value: @TwoDigitYear = '09'

This would give you something like '0118'. You then know that the next
registration number for that year should be '0119' (You could also
return the value incremented by one in SQL itself.)

rbr

unread,
Nov 19, 2009, 11:07:54 PM11/19/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
So, as you can see, there are many ways to solve this issue. I am
assuming you are trying to generate the Student_ID
on insert? A stored procedure would be best if possible.

In that case, I would do something very similar to what Cerebrus
recommended:

Begin

DECLARE @RowCount int
DECLARE @StuNum varchar

SET @RowCount = (SELECT COUNT(1) from Student_Details where datepart
(year, Dateof_Admission)= datepart(year, @Dateof_Admission))

SET @StuNum = (select 'T' + right(DATEPART(yy, current_timestamp), 2)+
'-' + RIGHT('00' + CAST(@RowCount AS varchar(3)), 3))

INSERT Student_Details
(
Student_ID,
Fname,
Lname,
Full_Name, --
Address,
DOB,
ContactNO,
email,
additional_detail,
Course_ID,
Dateof_Admission,
Dateof_Graduation
)
VALUES
(
@StuNum,
@Fname,
@Lname,
@Full_Name, --
@Address,
@DOB,
@ContactNO,
@email,
@additional_detail,
@Course_ID,
@Dateof_Admission,
@Dateof_Graduation,
)

END

Let me know if this workd for you. I'm sure we can figure something
out.

rbr
> > Thanks- Hide quoted text -
>
> - Show quoted text -

Raghupathi Kamuni

unread,
Nov 19, 2009, 11:25:22 PM11/19/09
to dotnetde...@googlegroups.com
select
RIGHT('00' + CAST(@RowCount AS varchar(3)), 3)
 
Maximum students allowed per year 999 ONLY !!

Nuwan Silva

unread,
Nov 20, 2009, 8:03:59 AM11/20/09
to dotnetde...@googlegroups.com

CREATE PROCEDURE crttdID(@RowCount int, @StuNum varchar OUTPUT)
AS
BEGIN
DECLARE @Dateof_Admission datetime
SET @RowCount = (SELECT COUNT(1) from Student_Details where datepart(year, Dateof_Admission)= datepart(year, @Dateof_Admission))
SET @StuNum = (select 'T' + right (DATEPART(yy, current_timestamp), 2)+ '-' + RIGHT('00' + CAST(@RowCount AS varchar(3)), 3))
END;


a put this in the sql file and tested it but only "T" will print

and one more thing i need to insert the StudentID to the Student_Details table without creating another table



2009/11/20 Raghupathi Kamuni <raghu...@gmail.com>

Raghupathi Kamuni

unread,
Nov 21, 2009, 5:48:01 AM11/21/09
to dotnetde...@googlegroups.com
DECLARE
@RowCount INT

SET
@RowCount = 999
SELECT RIGHT('00' + CAST(@RowCount AS varchar(3)), 3)  -- Prints 999

SET @RowCount = 1000
SELECT RIGHT('00' + CAST(@RowCount AS varchar(3)), 3)  -- Prints 00*

Nuwan Silva

unread,
Nov 22, 2009, 7:57:02 AM11/22/09
to dotnetde...@googlegroups.com
so i tried and tried and got this...

// --- Calculations >> Student Details >> Registration Number ---

string stdyr = DateTime.Now.Year.ToString();
stdyr = stdyr.Substring(2);

   
string stdno = how can i increment this for every insertion?

string stdid = ("T" + stdyr + "-" + stdno);

as said i need T09-001..... T09-0123..... T09-0299....



2009/11/21 Raghupathi Kamuni <raghu...@gmail.com>

vinay kumar

unread,
Nov 24, 2009, 2:14:06 AM11/24/09
to dotnetde...@googlegroups.com
use the max method for stdno and stdyr and one to it in sql 

Budi Sentosa

unread,
Nov 24, 2009, 6:23:08 AM11/24/09
to dotnetde...@googlegroups.com
have u got the last number / max number

just add 1

Nuwan Silva

unread,
Nov 24, 2009, 8:00:54 AM11/24/09
to dotnetde...@googlegroups.com
theres no max have to increment at least till 500 thats all.


2009/11/24 Budi Sentosa <b.budi....@gmail.com>

Budi Sentosa

unread,
Nov 25, 2009, 1:58:38 AM11/25/09
to dotnetde...@googlegroups.com


At first the row is 0
When the row is 0. U have to set the number to T09-001

When the second student register
U take the max number in db. Which u got number 1

U just add 1. So the number become 2 = T09-002

And so on

On Nov 25, 2009 12:32 PM, "Nuwan Silva" <nu1s...@gmail.com> wrote:

theres no max have to increment at least till 500 thats all.


2009/11/24 Budi Sentosa <b.budi....@gmail.com>

> > have u got the last number / max number > > just add 1 > > > On Tue, Nov 24, 2009 at 2:14 PM, v...

-- Thank You, Best Regards, Nuwan S. Silva 170, St. Anthony's Road, Moratumulla, Moratuwa, Sri ...

Peter Smith

unread,
Nov 25, 2009, 4:38:26 PM11/25/09
to dotnetde...@googlegroups.com
On Wed, Nov 25, 2009 at 1:58 AM, Budi Sentosa <b.budi....@gmail.com> wrote:


At first the row is 0
When the row is 0. U have to set the number to T09-001

When the second student register
U take the max number in db. Which u got number 1

U just add 1. So the number become 2 = T09-002

And so on

Until someone drops out, and this simple solution decides to delete the record.

 

Reply all
Reply to author
Forward
0 new messages