Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2008, 10:43 PM
Registered User
 
Join Date: Jan 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default generate unique id

hi ,

i have a table with name information which contain field

(patient id
name
address)

which contain datatype

patid int
name varchar
address varchar

patid is primary key and his identity is 1


so it contain data

patientid name address

1 john xyz
2 mark abc
3 kam rtg

the problem is that i need patientid in this way

patientid name address

patid_1 john xyz
patid_2 mark abc
patid_3 kam rtg
. .
. .
. .


how i generate id in this format
i have no idea how i can do this .plz someone help me










 
Old April 6th, 2008, 10:18 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

This is wrong for so many reasons, there's not enough room to list them all on this simple forum. However, there is a way to do this without causing the damage it'll do in the future. Create a calculated column that "feeds" off the PatientID column... Something like this...

Code:
ALTER TABLE Patient --Assuming your table name is "Patient" because you didn't say
ADD PatID AS 'PatID_'+CAST(PatientID AS VARCHAR(10))
It can also be indexed and used as an "Alternate key" for foreign key and performance reasons...
Code:
CREATE UNIQUE INDEX IXU_Patient_PatID
ON jbmTest (PatID)
--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Generate Unique values for IDs mphare XSLT 7 November 6th, 2008 12:20 PM
Create Unique Id langer123 Classic ASP Basics 0 April 6th, 2005 01:27 PM
Creating a Unique ID for each row maxworlund SQL Server DTS 1 March 8th, 2005 09:33 PM
Getting Unique ID from Database Nicky_uk Classic ASP Databases 9 January 26th, 2005 04:45 PM
Generate unique ID when populating a table sroman SQL Server 2000 2 August 5th, 2003 03:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.