Skip to content

Identity column in table

Ani

Asked Jul 24, 2017, 3:05 AM EDT5 answers
Share
LinkedInX
hi,
 
I have bulk data and i have insert them into a new table with identity column like as below
identity row should be A1 for first 100 rows, A2 for second 100 rows, A3 for third 100 rows, etc...........
 
Please help me
 
Thanks,
Ani

5 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Rafnas T P
    +1
    hi,
    first of all, Identity column will no insert same value more than once,
    here you mentioned that you want identity column value  A1 for first 100 rows
    like 
    A1
    A1
    .
    .
    100 times 
    this is not possible for identity column or primary key column
    +1
  • 0
    Hi Rafnas,
     
     Thanks for your suggestion.
    Please let me know is there any way to do it without identity column and primary key.
     
     
    Thanks,
    ani 
    0
  • Rafnas T P
    0
    well you can do it through looping, but you can not use this as primary key,or identity key
    0
  • Rafnas T P
    0
    try like this in your insert statement instead of that column value add this line
     
    case when (select count(*) from yourtablename)<=100 then 'A1'
    when (select count(*) from yourtablename)<=200 then 'A2' when (select count(*) from yourtablename)<=300 then 'A3 'end
    0
  • 0
    hi,
    Insert Id for new table from old table
    Insert Into <NewTable> (Id) values( 
    select 'A'+Convert(varchar,ID/100+1) from <OldTable>)
    0