lundi 2 août 2021

Create a condition to replace string in a column with strings from other column of different table in SQL

Not sure if I am framing this question right. I need some help with creating a select query in MS SQL Server, where I can replace strings in Table A > Values column with strings from a Table B > Deliverables.

The Table A > Values are specifically named as Deliverable 01, 02 and Table B > Deliverables are written something like D1: ABC, D2: DEF for some project IDs and Deliverable 1: ABC, Deliverable 2: DEF for other project ID

I am not looking for the obvious joins.

I am actually doing this for Crystal reports where I need to put some sort of condition where whenever there is a Deliverable 01 from Table A, replace it with D1: ABC or Deliverable 1: ABC based on the Project No.

I am guessing it might require some string manipulation, but how to do that?

For eg:

Table A

   Project ID      Value
    100            Deliverable 01
    100            Deliverable 02
    100            Deliverable 03
    100            Deliverable 04
    :
    :
    100            Deliverable 11 
-------------------------------------
    101            Deliverable 01
    101            Deliverable 02
    101            Deliverable 03       
    101            Deliverable 04

Table B

    Project ID      Deliverables
    100            D1: ABC
    100            D2: DEF
    100            D3: GHI
    100            D4: PQR
    :
    100            D11:XYZ 
-------------------------------------
    101            Deliverable 1: ABC
    101            Deliverable 2: DEF
    101            Deliverable 3: GHI       
    101            Deliverable 4: PQR
    101            Deliverable10: XYZ
   

Aucun commentaire:

Enregistrer un commentaire