alejandro carnero
alejandro carnero

Reputation: 1784

Same value in two columns of same table

I have this table

    NAME           TYPE 
   codigo        numeric
   referencia    varchar 

   codigo         referencia
    3018        7898379460494
    3062        7897840302639          
    3064        7897840300154

i want to write a select like this :

    select CODIGO, REFERENCIA, DESCRICAO  from ESTOQUE where CODIGO like REFERENCIA 

to know if have rows where codigo and reference have the same value

Upvotes: 0

Views: 81

Answers (4)

alejandro carnero
alejandro carnero

Reputation: 1784

Thanks to all

          select CODIGO, REFERENCIA, DESCRICAO  
         from ESTOQUE 
         where convert(varchar(max),CODIGO) = REFERENCIA

thas code work perfect.

Upvotes: 0

Lucas_Santos
Lucas_Santos

Reputation: 4740

select CODIGO, REFERENCIA, DESCRICAO  from ESTOQUE where CODIGO = cast(ESTOQUE.REFERENCIA as varchar(max))

Upvotes: 0

Adrian Wragg
Adrian Wragg

Reputation: 7401

You should be able to do:

select CODIGO, REFERENCIA, DESCRICAO  from ESTOQUE
    where convert(varchar, CODIGO) = REFERENCIA

Upvotes: 0

Avitus
Avitus

Reputation: 15968

select CODIGO, REFERENCIA, DESCRICAO  
from ESTOQUE 
where convert(varchar(max),CODIGO) = REFERENCIA

Upvotes: 2

Related Questions