473,609 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prefix word to autoincrement

pradeepjain
563 Contributor
Hi,
I have a mysql table where in i have a field called patient_id which i do an auto increment and its the primary key !! since this number goes on patient card also simply 1,2 will not be gud . Is there a way to prefix some text to it like patient1, patient2 something like that!!!
Sep 10 '09 #1
6 14528
Dormilich
8,658 Recognized Expert Moderator Expert
if it were possible to read the auto increment value in the insert process, you could use a function. you should ask the people in the MySQL forum if that’s possible.
Sep 10 '09 #2
Atli
5,058 Recognized Expert Expert
Sure:
Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT('patient', `patient_id`) FROM `patient_table`
Sep 10 '09 #3
pradeepjain
563 Contributor
@Atli
You got ma question wrong ! while auto_incrementi ng can we prefix some text to the autoincremented value!!!?
Sep 10 '09 #4
Atli
5,058 Recognized Expert Expert
@pradeepjain
Not directly, no. AUTO_INCREMENT only works on integers.

You could create a function that would get the next value for you and use that instead of an AUTO_INCREMENT field.

I wouldn't recommend it tho. You shouldn't format the data like that before inserting it. That sort of thing should be done on the way out, preferably by the front-end code (or in a simple query, like I posted before).
Sep 10 '09 #5
pradeepjain
563 Contributor
so which is the best way to generate ID numbers!!
1. remove auto_increment .
Store a basic value as patient001 and then get the value from DB and then increment and send it to DB again for next record

or

2 . let it be auto_increment only !! while displaying to user prefix some text and show it to user!
Sep 11 '09 #6
Atli
5,058 Recognized Expert Expert
#2

There is no good reason for storing "patient001 " in the database rater than "1".
Keep the database as simple as possible and do stuff like that (adding "patient") in the applications that require it.

I mean, what if, in the future, a second application was to use the same database, but needed the output to read "client001" rather then "patient001 "?
By storing the number only, that is a piece of cake. By storing the "patient" prefix, it becomes a big mess.
Sep 11 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

41
6073
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there is one row containing picture(s) as well. So far, what I did is doing it manually for each word docs I have. Select Table Convert Table to Text(I use ^ character for delimiter)
0
1398
by: Neil | last post by:
Hi, I'm getting some strange results using the autoincrement column on my datatable. I'm populating a datatable with data from my database and displaying this in a datagrid. The first time I get the data from the database I create a new table with an autoincrement column bind the datagrid to this new table. The auto increment column is displayed as an ID col in the datagrid. The user can add records or modify records at this point, when...
6
16116
by: Dennis | last post by:
I have set a DataTable and one of the columns I set "AutoIncrement" to True. I then populate the Table by setting the columns to values then add the row to the table. I inadverently set the AutoIncrement Columns to different values but didn't get any errors. Should I be able to set the value of an AutoIncrement Column? I would have thought it couldn't be done as the column value was set when a row was added. -- Dennis in Houston
6
9163
by: Michael | last post by:
I am trying to create an access database within Net 2003 using the ADOX library which works fine except when I try to add the AutoIncrement property to the ContactId column. I am experiencing a Property 'item' is ReadOnly error within the below line .Columns("ContactId").Properties("AutoIncrement") = True Am I missing a reference or what am I doing wrong?????
5
8065
by: JC Voon | last post by:
Hi: How to reset the autoincrement value generated by DataTable ? I've master and detail table, the detail table has a autoincrement column, each time i add a new master record, i need to reset the detail table autoincrement column to start from 1. I set the dataColumn AutoIncrementSeed=0 and AutoIncrementStep=1 each time i append a new master row, but it seem not work, it still remain
6
2195
by: jimryder | last post by:
Hi, The following snippet: (ds is a populated dataset) string sXSLT = @"C:\XML\template\template.xsl"; string sTemp = @"C:\XML\temp\temp.xml"; string sOutput = @"C:\XML\output\output.xml"; ds.WriteXml(sTemp);
1
3428
by: Mike | last post by:
I have a form that has an embedded subform (Datasheet View) that are linked based on a 1-many ID field. I have a field (SET) in my embedded subform that I want to Autoincrement starting with 1...and adding 1 to every new record. The Autoincrement needs to be separate for each ID. For example when I go to the form and enter a new record in the main form, the SET field should start over at 1 as a default and continue (+1) for each new...
4
2446
by: Tim | last post by:
Hello All, I could use some help on an error that is just now popping it's head up. Seems that the autoincrement numeric has hit 32,767. The autoincrement is used in various locations in the database, but in this case (log sheets), we have hit 32k log entries over the past 2 years. Is there a simple switch to set the autoincrement from integer to long integer?
1
3756
rizwan6feb
by: rizwan6feb | last post by:
I have a DataTable with thousands of records, i want to show these records on per page basis ( i.e a DataGridView showing first 20 records and next button to show next 20 records ...) To achieve this, i have added an Autoincrement Column to the DataTable so that i can use a filter on the Autoincrement Column to get the desired 20 records from the DataTable. I have used the following code Dim dc As New...
0
8117
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8557
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8516
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6048
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4007
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1375
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.