lundi 15 janvier 2018

sql server set column value depend on other column's value

I declare three string array like

Declare @first varchar(50)
set @first = 'firstValue1,firstValue2,firstValue3,firstValue4,firstValue5'
Declare @second varchar(50)
set @second = 'secondValue1,secondValue2,secondValue3,secondValue4,secondValue5'
Declare @third varchar(50)
set @third = 'thirdValue1,thirdValue2,thirdValue3,thirdtValue4,thirdValue5'

I have two table myTableOne and myTableTwo.
I joined those two table and select the columns category and title .

   select t1.category , t2.title from myTableOne t1
    inner join myTableTwo t2 on t1.id = t2.t1id

What I want to do is , if t2.title contains in @first array, I want to set (update) value of t1.category to first. Like this

if `t2.title` contains in @first ==> set t1.category to `first`
if `t2.title` contains in @second ==> set t1.category to `second`
if `t2.title` contains in @third ==> set t1.category to `third`

Aucun commentaire:

Enregistrer un commentaire