Pittsburgh Business Daily

How can I output replaced values in a query to the same output column?

How can I write a querie that gives me the information from two tables but replacing the output of one column with different values. For example Table A A B C Table B 1 2 3 I want to get(replacing: 1=Medication, 2=Diagnostic, 3=other): A Medication B Diagnostic C Other I've used the replacement syntax, but that creates a different column for each replacement value. Thank you for any info you might have.

Public Comments

  1. Mkay, I don't know the structure of your table nor the relationships so i am going to take a couple stabs at this to try and cover the bases if your tables are related by primary key, foreign key then you can use a case statement to decide on what is shown for values in table 2: SELECT a.col1, case b.col when 1 then 'Medication' when 2 then 'Diagnostic' when 3 then 'other' end FROM TABLEA a INNER JOIN TABLE b on a.PrimaryKeyCol = b.ForeignKeyCol if you want one column for all results then you can use this SELECT a.col1 + ' ' + case b.col when 1 then 'Medication' when 2 then 'Diagnostic' when 3 then 'other' end FROM TABLEA a INNER JOIN TABLE b on a.PrimaryKeyCol = b.ForeignKeyCol HOWEVER if 1, 2, 3 are how A, B, and C are related to Medication, Diagnostic, other then: (assuming that Medication, Diagnostic, other are in 'col2', AND that 1, 2, 3 are ids (col1) which are also stored as foreign keys (references) on TableA in an assumed col2) SELECT a.col1, b.col2 FROM Table1 a INNER JOIN Table2 b on a.col2 = b.col1 If i didn't nail it then please email me with more information about the table structure and how the data is related and I will be happy to help you with your sql query.
Powered by Yahoo! Answers