How to Take data from an SQL table by referencing only the first position of the VARCHAR type

Asked

Viewed 43 times

1

I need to delete everything that starts with '9' in my seg1 column, for example:

If in the table this '954747A' will be eliminated because the 9 is the first position.

If you have '34465922A' It doesn’t have to be deleted.

The logic I was doing is killing everything related to 9.

Segue Query:

SELECT DISTINCT A.SEG1 ||'-'|| a.SEG2 ||'-'|| A.SEG3
FROM TB_TESTE
WHERE A.SEG3 NOT LIKE '%C%'   
   AND A.SEG3 NOT LIKE '%D%' 
   AND A.SEG3 NOT LIKE '%E%' 
   AND A.SEG3 NOT LIKE '%F%'  
   AND A.SEG3 NOT LIKE '%G%' 
   AND A.SEG1 NOT LIKE '%9%';
  • Could you put how it returns, and what is related in SEG1? where this numbers Voce wants to eliminate, because in case would a notlike"%9" in the case

  • DELETE FROM TB_TESTE WHERE SEG1 LIKE '9%';

  • @anonimo I cannot delete everything from table I put only an abbreviation of table name now as example.

  • @anonimo is an important table, I am making this rule only for that system. but in others it is used normally. but obg by the help

  • But the above command is in line with what you said in "I need to delete everything that starts with '9' in my Second column". Unless by "delete" you mean "do not recover", in this case replace DELETE with SELECT.

1 answer

0


Try something like this because the LIKE with the % at the beginning will catch only those that start

SELECT DISTINCT A.SEG1 ||'-'|| a.SEG2 ||'-'|| A.SEG3
FROM TB_TESTE
WHERE A.SEG3 NOT LIKE '%C%'   
   AND A.SEG3 NOT LIKE '%D%' 
   AND A.SEG3 NOT LIKE '%E%' 
   AND A.SEG3 NOT LIKE '%F%'  
   AND A.SEG3 NOT LIKE '%G%' 
   AND A.SEG1 NOT LIKE '%9';
  • It worked out, thank you very much. I don’t even know how to thank you

  • if you can put as correct answer, kkk I’m happy to help :)

  • Like my friend, I just can’t seem to rate you :( if I didn’t give you 1 point

Browser other questions tagged

You are not signed in. Login or sign up in order to post.