Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Identity Column

Author  Topic 

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-07 : 03:32:40
Can we change a identity column to a varchar through coding.
the column name is EMPID table name Emps

KaShYaP

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 03:37:49
Can you make more clear what you want to do?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 03:39:21
Maybe this helps:
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-07 : 03:52:27
Mr.fred
Actually if we make any data deletion in the table the sequence of the identity column will be changed. If we can insert the data them we will modify it.
Ex:- Empid is 1,2,3,4....N. If we delete some data of some rows i,e 6,7,8 rows have deleted then the sequence of the numbers will be changed.
So, I am asking if we add data into identity column like giving empid 6 then we will get in a sequential manner

KaShYaP
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 03:59:16
Ok that has nothing to with changing the column to varchar.
Why do you bother about the sequence of that identity column?
Gaps? That should be nothing to care about.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 04:01:14
for that you need to set identity insert on and pass a explicit value. Actually you dont need to worry about it as you can still get data in order you want with gaps.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-07 : 04:01:17
So you want an ID that has no gaps?

This will change over time of course, so you cannot use it as the sense of "Employee ID" - you will need another, non changing, field for that.

Is this just for reports? If so a sequential "row number" can be generated at the time you select the data - would that do instead?
Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-07 : 04:16:06
Thank You all for considering

KaShYaP
Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-07 : 04:34:24
Mr.Visakh16
Can you give coding of the statement of yours Plz

KaShYaP
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 04:42:25
quote:
Originally posted by kashyapsid

Mr.Visakh16
Can you give coding of the statement of yours Plz

KaShYaP


something like

SET IDENTITY_INSERT yourTable ON

INSERT INTO yourTable(IDColumn,othercolumns..)
VALUES(@ReqdIDvalue,...)

SET IDENTITY_INSERT yourTable OFF


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-07 : 04:46:32
Just to check:

1) Is this the main Employee ID that people / computer programs refer to the record by?

or

2) is it just a "Row number" so you can display the employees "in order"?
Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-07 : 07:55:25
it is a computer program automatically generating the EmpId number

KaShYaP
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-07 : 09:07:14
So ... if someone leaves you want to re-use their number for a new employee?

Why not just allocate them the next number (ignoring any numbers / gaps for people who have left)?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-07 : 12:46:50
you will at least avoid difficulty of doing this manually by just making it identity and not worrying abt gaps

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kashyapsid
Yak Posting Veteran

78 Posts

Posted - 2010-04-08 : 01:00:33
ok thats fine thanks once again

KaShYaP
Go to Top of Page
   

- Advertisement -