0

I do have a table scenario in SQL Server 2012 that allows me to concat a column from its properties "computed column specification" especially when creating a new record where my table has the following columns design format

[VIndex] [int] IDENTITY(1,1) NOT NULL
[VISTORID] AS (concat('PD', str([VIndex], len([VIndex]), (0)))) PERSISTED NOT NULL

In which case when the Vindex auto increments, the vistorId column will pick that information and add characters to it to create another unique id

For example

VIndex  VISTORID
  1     PD0001
  2     PD0002
  3     PD0003
  4     PD0004

The problem am having is in SQL Server 2008, under column properties the "computed column specification" does not allow or recognize concat. I have completely run out of ideas, when I script this database to SQL Server 2008, it won't accept so any table having this property is dropped.

How do I solve this problem?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bels
  • 85
  • 8

1 Answers1

0

In SQL Server 2008 you would do something like

CREATE TABLE Test_Table 
 (   
   [VIndex] [int] IDENTITY(1,1) NOT NULL
  ,[VISTORID]  AS ('PD' +  RIGHT('0000' + CAST([VIndex] AS VARCHAR(4)),4))  
                                                                      PERSISTED NOT NULL
 )
M.Ali
  • 67,945
  • 13
  • 101
  • 127