1

I need to move some data from one DB to another but as the layout is not the same, I need a to add a condition to this:

If Genderbit == 1 (from CRM.dbo.Person), a string 'M' should be inserted into ewa.Ansprechpartner.Gender, else a string 'F' should be used.

USE easyWinArtTest
GO

INSERT INTO ewa.Ansprechpartner(Vorname, Nachname, Email, Telefon, Telefax, Gender)
   SELECT Forename, Surname, EMailAddress, Phone, Fax, [genderbit]
   FROM CRM.dbo.Person

How is this done with SQL Server?

2 Answers 2

3

Try this:

INSERT INTO ewa.Ansprechpartner(Vorname, Nachname, Email, Telefon, Telefax, Gender)
   SELECT 
       Forename, Surname, EMailAddress, Phone, Fax,
       CASE [genderbit]
          WHEN 1 THEN 'M'
          ELSE 'F'
       END
   FROM 
       CRM.dbo.Person

Use a CASE statement, based on the Genderbit column - if it's 1 then use M to be inserted, else F

Sign up to request clarification or add additional context in comments.

1 Comment

@861051069712110711711710997114: decades of practice :-)
0

You can use a case statement in the select query to do the conditional substitution like so:

USE easyWinArtTest
GO

INSERT INTO ewa.Ansprechpartner(Vorname, Nachname, Email, Telefon, Telefax, Gender)
SELECT Forename, Surname, EMailAddress, Phone, Fax,Case when genderbit = 1 then 'M' else 'F' end
FROM CRM.dbo.Person

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.