good afternoon I am starting to create some SP in sql server for a school practice and I encountered a problem when assigning the result to a local variable, I leave you my code and hoping you can help me
alter procedure sp_Nombre_Cliente (@id int)
as
begin
set nocount on
declare @registros int
set @registros =(select COUNT(*) from Cliente c where c.ID_CLIENTE=@id ) //aqui siento que tengo el problema
if @registros < 0
print 'existe'
else
print 'mo existe'
end
to any id that I send it goes to does not exist even though it does exist in the base I hope you can help me
The validation you have will never work correctly, since the COUNT never returns less than 0, if an item does not exist it returns 0, and if it finds records it returns the number of records located.