Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add alphanumeric identity column

Posted on 2014-01-22
2
Medium Priority
?
335 Views
Last Modified: 2014-01-23
I want to add a column to my table that takes the value of the identity column and prefixes it with 'A'. I don't know the syntax for specifying the varchar datatype within this statement:

ALTER TABLE T_MyTable 
ADD ID2 AS 'A' + ID

Open in new window

0
Comment
Question by:TimHudspith
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39802427
You want something like:
ALTER TABLE T_MyTable
   ADD [ID2]  AS ('A'+CONVERT([varchar],[ID],0))

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39802451
I confirm the above. it's not only a technical limitation, but also a matter of normalization of database tables
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question