Link to home
Start Free TrialLog in
Avatar of fcobuzzi
fcobuzzi

asked on

If or Case Statement

Hi,
I'm trying to write a script that will do the following:
It will verfiy what code is in Table A and then it will write a pre determined number into Table B.

Example:
Table A Codes
HRT
HRA
OA

So if the code in Table A is HRT it will write 8 into Table B.

I don't know if I should use If or Case statement.

TIA,

Frank
Avatar of rafrancisco
rafrancisco

Just for clarification, if Table A has a code of HRT, how many records will be inserted in Table B?  Just 1 or depends how many times HRT exists in Table A?

If you just want a record inserted to Table B if there's a HRT in Table A, this should work:

INSERT INTO Table B
SELECT 8
WHERE EXISTS (SELECT 'X' FROM TableA WHERE Code = 'HRT')
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial