Query where result equals any of the values in the list

Asked

Viewed 40 times

0

I have a table of Duplicates that has the month reference as string,(ex: 01/2012, 05/2016 and etc)

And I need to perform a query between a date range, if the field was Datetime I know it would be enough to use >= and <= but being a string with month and year, how can I pass a parameter with a list containing the dates I want

select * from(select ID,Duplicata,IF(Modelo ='C','Corretor',if(Modelo = 'S','Supervisor','')) as 'Tipo',(select corr_nome from corretores where corr_id = comissionado) as 'Comissionado', Valor from comissao)A1
 where (select dup_mes from duplicatas dup_mes= /*<LISTA DE VALORES QUE QUERO PESQUISAR>*/

P.S. The list will contain the values of the date range(01/2017, 02/2017, 03/2017)

1 answer

1


You can try to use the claúsula IN in his SELECT. Ex:

select dup_mes from duplicatas dup_mes IN ('01/2017', '02/2017', '03/2017')
  • 1

    Philip, I think we missed a "Where" there, no?

  • I only took the subselect part to exemplify the use of the IN, I didn’t take all the SELECT. But it would be something like this: select * from(select ID,Duplicata,IF(Modelo ='C','Corretor',if(Modelo = 'S','Supervisor','')) as 'Tipo',(select corr_nome from corretores where corr_id = comissionado) as 'Comissionado', Valor from comissao)A1&#xA; where (select dup_mes from duplicatas dup_mes IN ('01/2017', '02/2017', '03/2017'))

  • @Filipemartins had put the end as an example because he didn’t know if another command would replace select, but in this case it only worked by putting Where before Dup_mes, it would be interesting to update the answer to anyone who searches for it to have the answer 100% ok! thanks for saving me haha

Browser other questions tagged

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