I'm getting this error on a SQL user defined function:
An expression of non-boolean type specified in a context where a condition is expected, near ')'.
For this:
UPDATE LMI_Contact SET Phone = NULL WHERE dbo.LMI_IsSingleCharacterRepeated(Phone, '0')
where the function can be created using:
-- ***this will also find NULL and empty string values*** CREATE FUNCTION LMI_IsSingleCharacterRepeated (@string varchar(max), @char char(1)) RETURNS bit AS BEGIN DECLARE @index int DECLARE @len int DECLARE @currentChar char(1) SET @index = 1 SET @len= LEN(@string) WHILE @index <= @len BEGIN SET @currentChar = SUBSTRING(@string, @index, 1) IF @currentChar = @char SET @index= @index+ 1 ELSE RETURN 0 END RETURN 1 END; GO
This function is for checking if a string is any specified single character, repeated.
CREATE OR REPLACE FUNCTION fun_tiene_cita (id_paciente number, fecha_cita date) return number is begin if (exists(select id_paciente from citas where id_paciente = 500 and fecha_cita = 03/03/2020)) then return 'true'; else return 'false'; end if; END fun_tiene_cita; Obviously, it isn't working, so, what could I do?
You can not use Stored Procedure in where clause but can use User Defined Function in where clause.
You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
You must use comparison operators against functions even if the return type is bit
.
UPDATE LMI_Contact SET Phone = NULL WHERE dbo.LMI_IsSingleCharacterRepeated(Phone, '0') = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With