Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:58:36+00:00 2026-06-13T01:58:36+00:00

Hello guys here with another question, regarding sql server 2008 r2 this time about

  • 0

Hello guys here with another question, regarding sql server 2008 r2 this time about the merge, is it possible to have a case inside the update portion of the merge?

Because its telling me

Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword ‘CASE’.

MERGE INTO PERSONAFISICA AS TARGET
USING dbo.#temp1 AS SOURCE
ON TARGET.RFC = SOURCE.RFC AND TARGET.APATERNO = SOURCE.APELLIDO_PATERNO AND
TARGET.AMATERNO = SOURCE.Apellido_Materno
WHEN MATCHED THEN
UPDATE SET
TARGET.NUM_CLIENTE = 0,
TARGET.NOMBRE1 = LEFT(SOURCE.Nombre,CHARINDEX(' ', SOURCE.NOMBRE + ' ') -1),
CASE 
WHEN LEN(SOURCE.NOMBRE) - LEN(REPLACE(SOURCE.NOMBRE,' ','')) >= 1
THEN 
TARGET.NOMBRE2 = SUBSTRING(SOURCE.NOMBRE, CHARINDEX(' ', SOURCE.NOMBRE)+1, LEN(SOURCE.NOMBRE))
ELSE '' END,
TARGET.APATERNO = SOURCE.Apellido_Paterno,
TARGET.AMTERNO = SOURCE.Apellido_Materno,
CASE 
WHEN SOURCE.SEXO = 'F' 
THEN TARGET.IDGENERO = 2
WHEN SOURCE.SEXO = 'M'
THEN TARGET.IDGENERO = 1
ELSE TARGET.IDGENERO = 0
END,
CASE
WHEN SOURCE.ESTADO_CIVIL = '0' 
THEN TARGET.idestado_civil = 0
WHEN SOURCE.ESTADO_CIVIL = 'C'
THEN TARGET.idestado_civil = 1
WHEN SOURCE.ESTADO_CIVIL = 'D' 
THEN TARGET.idestado_civil = 2
WHEN SOURCE.ESTADO_CIVIL = 'S'
THEN TARGET.idestado_civil = 3
WHEN SOURCE.ESTADO_CIVIL = 'V' 
THEN TARGET.idestado_civil = 5
WHEN SOURCE.ESTADO_CIVIL = 'U'
THEN TARGET.idestado_civil = 6
ELSE TARGET.idestado_civil = 0
END,
TARGET.idregimen = 0,
TARGET.saludo = SOURCE.SALUDO,
TARGET.conyuge_nombre1 = '',
TARGET.conyuge_nombre2 = '',
TARGET.conyuge_apaterno = '',
TARGET.conyuge_nombre2 = '',
TARGET.dependiente = 0,
TARGET.edad_dependiente = '',
TARGET.ididentificacion = 0,
TARGET.fecha_nacimiento = '1800-01-01',
TARGET.rfc = SOURCE.RFC,
TARGET.CURP = '',
TARGET.idnacionalidad = 0,
TARGET.email = SOURCE.Email_Personal,
TARGET.idescolaridad = SOURCE.Escolaridad
WHEN NOT MATCHED THEN
INSERT (num_cliente, nombre1, nombre2, apaterno, amaterno, idgenero, idestado_civil,
idregimen, saludo, conyuge_nombre1, conyuge_nombre2, conyuge_apaterno, conyuge_amaterno, dependiente,
edad_dependiente, ididentificacion, fecha_nacimiento, rfc, curp, idnacionalidad, email, idescolaridad)
VALUES (0, LEFT(nombre,CHARINDEX(' ',nombre + ' ')-1) AS [Primer Nombre],
CASE WHEN LEN(nombre) - LEN(REPLACE(nombre,' ','')) >= 1  THEN SUBSTRING(nombre, CHARINDEX(' ', nombre)+1, LEN(nombre)) ELSE '' END AS [Segundo Nombre],
Apellido_Paterno,Apellido_Materno)
CASE 
WHEN SEXO = 'F' THEN 2
WHEN SEXO = 'M' THEN 1
ELSE 0
END,
CASE 
WHEN Estado_Civil = '0' THEN 0
WHEN Estado_Civil = 'C' THEN 1
WHEN Estado_Civil = 'D' THEN 2
WHEN Estado_Civil = 'S' THEN 3
WHEN Estado_Civil = 'V' THEN 5
WHEN Estado_Civil = 'U' THEN 6
ELSE 0
END, 0, Saludo,'','','','',0,'',0,'1800-01-01',RFC,'',0,Email_Personal,Escolaridad
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:58:37+00:00Added an answer on June 13, 2026 at 1:58 am

    You can’t use a case in that way in an update. It needs to be like …

    UPDATE table
    SET value1 = CASE 
        WHEN a.blah = b.blah THEN foo
        WHEN a.blah > b.blah THEN bar
        ELSE NULL
      END,
    value2 = 5,
    ......
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Guys! I started learning python GUI development. Let's say I have this script:
Hello guys sorry if the question looks stupid to you. i have 3 tables
Hello struggling here guys.. Is it possible to string replace anything between the the
Hello guys i have a problem streaming PDF files with php, i'm using this
hello guys i have this function for focus : fav[jj].setOnFocusChangeListener(new View.OnFocusChangeListener() { public int
Hello guys I have this video tutorial on Ruby on Rails and I see
Hello guys I have this weird problem with Razor Syntax. I have written the
Hello guys i have dataform in silverlight 4 project item source is: ItemsSource={Binding Data,
Hello guys. I think it isn't possible just using PHP, but just to be
Hello guys i have set background image on my input text and text area

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.