Doubt over IF SQL and check if a select returns records [closed]

2

In a table called pacientes I have a Juan , which is varchar (4) .

My if has the following inconvenience Juan can be Pedro or José . That is, this name can vary many times I need a IF that enters Begin if Select shows result.

The following IF shows I believe only alpha-numeric in >0

I want that if select shows 'X' of result between Begin , what I had will be something like this

IF (SELECT Nombre FROM Tabla WHERE CEDULA)>0
BEGIN
PRINT 'Entro'
END 
ELSE
PRNT 'NO ENTRO'

Understand that for me I think that >0 "Greater than 0" does it mean Show amount of Rows Shown or am I wrong? Or does it show if the number of select is greater then enter?

How would it be written correctly?

I did this #Temp (Temporary Table) to see how it was but it did not work.

CREATE TAble #Temp 
(
NOMBRE varchar (250)
)

INSERT #Temp Values ('Juan');

IF (SELECT Nombre FROM #temp)>0
BEGIN
PRINT 'EXITO'
END
ELSE
PRINT 'NO EXISTE'

Very important the word juan are combinations of the A-Z osea thousands of combinations

I want a solution to the line

IF (SELECT Nombre FROM #temp)>0

this is taken as varchar and not as int

    
asked by Juan Carlos Villamizar Alvarez 24.09.2016 в 03:23
source

1 answer

2

To know the number of rows returned by a select, you would use the count (*)

IF (SELECT COUNT(*) from #temp)<>0 --Hay resultados
BEGIN
PRINT 'EXITO'
END
ELSE
PRINT 'NO EXISTE'
    
answered by 24.09.2016 / 03:58
source