0

Suppose i have table level as

ID  name    abbr    countryid
1   None    NN  11
2   Middle  MD  33
3   Senior  SN  33
4   Junior  JN  22

No i want to insert the records of countryid 33 in same table with countryid 44 (Countryid 44 will be input parameter).But how to insert data under column ID? as Id is autoincrement?

INSERT INTO Master_LevelsGrades(Id, LevelName, LevelAbbr, CountryId)
(
select  ?? ,LevelName,LevelAbbr,@NewCountryId
 from Master_LevelsGrades where CountryId=33
)
BTSQL
  • 51
  • 1
  • 4

1 Answers1

1

Just leave it out:

insert into Master_LevelsGrades (LevelName, LevelAbbr, CountryId)
    select  LevelName, LevelAbbr, @NewCountryId
    from Master_LevelsGrades
    where CountryId = 33;

It will be set automagically.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 1
    Hi @BTSQL, Welcome to stackoverflow! If this answer is the correct answer for your question, you should mark it as accepted so that everyone can immediately see that, even from outside the question page. – Johwhite Apr 10 '19 at 12:35