[Solved] Variable Declaration [closed]


Collect your error messages, if you get none return the result of your query, else return or raise the collected errormessages.

Declare @a Table (a int,b int,c int)

insert into @a Values(1,2,3),(4,4,4)

Declare @va int=2
Declare @vb int=2
Declare @vc int=2

Declare @error Varchar(100)=''
if not exists(select * from @a where a=@va)
   Select @Error=@Error + 'Invalid va ' + Cast(@va as Varchar(10)) + Char(13)+Char(10)
if not exists(select * from @a where b=@vb)
   Select @Error=@Error + 'Invalid vb ' + Cast(@vb as Varchar(10)) + Char(13)+Char(10)
if not exists(select * from @a where c=@vc)
   Select @Error=@Error + 'Invalid vc ' + Cast(@vc as Varchar(10)) + Char(13)+Char(10)
if len(@Error)>0 select @Error
else
  Select * from @a where a=@va and b=@vb and c=@vc

solved Variable Declaration [closed]