0

I have the following query:

Select PERSON_NAME, Mobile_Nr, replace(Message, 'text 8' ,'yes') as SMSs from PERSON a
    inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
    inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
    inner join MESSAGE_ID d on c.ID=d.ID_Mobile
    where a.Person_Name not in 
    (Select PERSON_NAME from PERSON a
    inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
    inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
    inner join CALL_ID d on c.ID=d.ID_Mobile)

It returns:

      PERSON_NAME           Mobile_Nr   SMSs
First name 5 Last name 5    797900012   yes
First name 5 Last name 5    797900012   text 9
First name 5 Last name 5    797900016   text 13

How can I change all the values in SMSs to Yes in my query?

6
  • What table is the 'Message' column in? Commented Apr 25, 2014 at 13:13
  • When should the query return a value other than 'yes'? Commented Apr 25, 2014 at 13:15
  • No conditions, it is just a requirement. It has to be in the select query. Commented Apr 25, 2014 at 13:16
  • No what I am asking is when do you want to not return 'yes'. When would you return 'no'? Commented Apr 25, 2014 at 13:17
  • 1
    If you always want yes, use Michael's answer Commented Apr 25, 2014 at 13:18

2 Answers 2

2

Not sure if I understood right. Is that what you want?

Select PERSON_NAME, Mobile_Nr, SMSs = 'Yes' from PERSON a
inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
inner join MESSAGE_ID d on c.ID=d.ID_Mobile
where a.Person_Name not in 
(Select PERSON_NAME from PERSON a
inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
inner join CALL_ID d on c.ID=d.ID_Mobile)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that works, I was just thinking too much on the REPLACE() function.
0

Is this what you want to do (assuming the 'Message' column is in the 'MESSAGE_ID' table)?

UPDATE MESSAGE_ID SET Message='Yes'
FROM PERSON a
inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
inner join MESSAGE_ID d on c.ID=d.ID_Mobile
where a.Person_Name not in 
(Select PERSON_NAME from PERSON a
inner join USER_MOBILE b on a.ID_PERSON=b.ID_USER
inner join MOBILE_NUMBER c on b.ID_MOBILE=C.ID
inner join CALL_ID d on c.ID=d.ID_Mobile)

1 Comment

The idea is correct but I want to keep the select. So I make the replace inside the select query.

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.