sql server - t sql call function as while parameter -
is possible in t sql use function while parameter? have following code:
create function loginexists (@p_login char(6)) returns varchar(5) begin if exists(select * student student.slogin = @p_login) return 'true' return 'false' end; and
create procedure addstudent2 (@p_fname varchar(30), @p_lname varchar(50), @p_tallness int) declare @p_login char(6), @p_email varchar(50), @suffix char(3); set @p_lname = lower(@p_lname); set @suffix = '000'; begin set @p_login = substring(@p_lname,1, 3) + @suffix; while (loginexists @p_login = 'true') set @suffix = cast((cast(@suffix int) + 1) char(3)); set @p_login = substring(@p_lname,1, 3) + @suffix; set @p_email = @p_login + '@vsb.cz'; insert student values (@p_login, @p_fname, @p_lname, @p_email, @p_tallness); end; and when trying compile it, error occurs, saying: "incorrect syntax near '@p_login'."
your syntax calling function in fact incorrect:
replace:
while (loginexists @p_login = 'true') with:
while (dbo.loginexists (@p_login)= 'true')
Comments
Post a Comment