Case Statement in an Insert clause

  • I need to insert a record into another dabase but can you use a Case statment in the value clause?

    Ex.

    insert into MY_DEV..Data2007 (DataGuid,RespID,County,Zip5,StateCode,Longitude,Latitude,SurveyLanguage,age,STCO,memberAge1,memberAge2,memberAge3,memberAge4,memberAge5,memberAge6,memberGender1,memberGender2,

    memberGender3

    ,memberGender4,memberGender5,memberGender6,memberRel1,memberRel2,memberRel3,memberRel4,memberRel5,memberRel6,memberHealth1,memberHealth2,

    memberHealth3

    ,memberHealth4,memberHealth5,memberHealth6,education,hispanic,race,maritalStatus,annualIncome,numberOfMembers,numberOfChildren,employed,

    industryCode

    ,isp,browser,SPEED,FIPS,CensusCode,OverSample,Year,EntireMarket,Phone,Demographic_id)

      select

     p.DataGuid,RespID,County,Zip,StateCode,Longitude,Latitude,SurveyLanguage,age,oFIPS,

    memberAge1

    ,memberAge2,memberAge3,memberAge4,memberAge5,memberAge6,memberGender1,memberGender2,memberGender3,memberGender4,

    memberGender5

    ,memberGender6,memberRel1,memberRel2,memberRel3,memberRel4,memberRel5,memberRel6,memberHealth1,memberHealth2,memberHealth3,

    memberHealth4

    ,memberHealth5,memberHealth6,education,hispanic,race,maritalStatus,annualIncome,numberOfMembers,numberOfChildren,

    employed

    ,industryCode,isp,browser,SPEED,oFips,

    case when statecode in (9,23,25,33,44) then 1 when statecode in (34,36,42) then 2 when statecode in (17,18,26,39,55) then 3 when statecode in (19,20,27,29,31,38,46) then 4 when statecode in (10,11,12,13,24,37,45,51,54) then 5 when statecode in (1,21,28,47) then 6 when statecode in (5,22,40,48) then 7 when statecode in (4,8,16,32,35,49,56) then 8 when statecode in (6,41,53) then 9 end,

    '2007', 0,0,0) Or something along these lines.

     

    Thanks

     

  • Yes, of course you can.

    Did you receive an error when you tried?

    If unsure, you can always start a transaction, execute statement, read uncommitted records and if satisfied, commit transaction.

     


    N 56°04'39.16"
    E 12°55'05.25"

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply