How to determine whether the value of a stored procedure variable is empty?

how do I determine whether the value of a stored procedure variable is empty? Mainly judge whether the input value of the employee"s field is empty. In another table, CMSFIE, I define which fields can be empty and which fields cannot be empty, and then take the value of this field in the preservation of the employee data to compare it with the empty flag stored in CMSFIE.

the simulation process is as follows:
create proc myepatest
@ EPA002 varchar (10),-- employee information field
@ EPA003 varchar (80),-- employee information field
@ EPA004 varchar (40)-- employee information field
as
declare @ R varchar (1000)
declare @ fieldname varchar (10)-- name of the field stored in the CMSFIE table
declare @ nsql nvarchar (1000)

declare mycursor cursor for
select (substring (FIE003,1,6)) Field from CMSFIE where FIE002="vCMSEPA" and FIE019="1" / / read the required field name from the CMSFIE table

open mycursor

fetch next from mycursor into @ fieldname

while (@ @ FETCH_STATUS=0)
begin

  set @nsql="if (@"+@fieldname+"="""") or (@"+@fieldname+" is null)  set  @R=""x"" else set @R= ""y"" "
  EXEC(@nSQL)
  fetch next from mycursor into @fieldname

end
close mycursor
deallocate mycursor

-Executive Times error @ EPA002,@EPA003, @ R variable does not define
how to define

Feb.26,2021

obviously no value is passed through

make a decision whether it is empty or not, and then assign the default value

solve

Menu