Check following record BD (Vb.Net)

0

I expose my doubt, I have a Vb.net application, in which a label marks a condition of 1 or 2, if it is 1, I insert a record in a field of a BD that has a busy field = 0, but if it is 2, I need you to look for two contiguous fields with the occupied field = 0 and to insert the same information in the two fields.

The format of the fields is:

I would need you to search for the first two contiguous fields that have occupied = 0.

I've been thinking about it for a while and I do not know how to do it

    
asked by Jorge Salas Bernal 16.08.2018 в 13:11
source

2 answers

0

If at the end of the account you need the first two of your selection you could use a TOP as I show below

SELECT TOP 2 * FROM TABLA WHERE ocupado = 0

I hope I will help you and mark them as useful. Greetings.

    
answered by 16.08.2018 в 14:49
0

Bearing in mind that the field is alphanumeric, I enclose the following solution.

SELECT TOP 1 PB.NOM_HUECO,PB2.NOM_HUECO
FROM TABLA PB
INNER JOIN TABLA PB2 
ON PB2.NOM_HUECO = 'A'+ CONVERT(VARCHAR,SUBSTRING(PB.NOM_HUECO,2,10)+1)
WHERE PB.OCUPADO = '0' AND PB2.OCUPADO = '0'
ORDER BY 1 ASC

I hope it helps you!

    
answered by 16.08.2018 в 15:41