I must make a query to a code but in the BD is the code with zeros on the left

1

Example I must consult this code 2365 but in the BD is this 00000002365 how can I make the query just by writing the code 2365 without the zeros?

I am working on visual studio 2015 with BD Oracle.

"SELECT * FROM MOVIMIENTOCONTABLE WHERE CTERCERO = '" + TBNit.Text + "'AND CTIPO = '" + comboBoxTipo.Text + "' AND CNUM = '" + TBCausacion.Text + "'";

I must remove the zeros for TBNit.Text and TBCausacion.Text

    
asked by Saul Salazar 09.08.2018 в 22:46
source

2 answers

1

If you are using Oracle then you can use the function LTRIM , the LTRIM function of Oracle allows you to define a field and the character to the left that you want to remove, for example:

LTRIM(NOMBRE_COLUMNA, '0')

Attach an example query:

SELECT *
FROM TABLA_1 T1
JOIN TABLA_2 T2
ON LTRIM(T1.CODIGO_T1, '0') = LTRIM(T2.CODIGO_T2, '0');

I also show you a couple of executions with your results:

LTRIM('000123', '0')
Resultado: '123'

LTRIM('123123Tech', '123')
Resultado: 'Tech'

I hope it is of your help. Greetings.

    
answered by 09.08.2018 / 22:52
source
0

You have to use the operator LIKE like this:

"SELECT * FROM TERCEROS WHERE TrTERCERO LIKE '%" + TBNit.Text + "%'"
    
answered by 09.08.2018 в 22:53