Change the line:
SET @myDesc =
EXEC UDSPRBHPRIMBUSTYPESTARTUP @CODE = @myCode, @DESC = @@tempDesc OUTPUT
to
EXEC UDSPRBHPRIMBUSTYPESTARTUP @CODE = @myCode, @DESC = @tempDesc OUTPUT
And you have missed assigning @DESC
in the stored procedure.
SET @SQL =
'SELECT @DESC = clnt_cat_desc FROM ' + @SERVERNAME +
'.' + @DBASE + '.dbo.hbl_clnt_cat WHERE inactive = ''N''
AND clnt_cat_code = ''' + @CODE + ''''
EXECUTE sp_executeSQL @SQL, N'@DESC varchar(255) output', @DESC output
You should then use @tempDesc
in the next select:
SELECT
a.clid
, b.fileid
, c.usrfullname AS ClientPartner
, e.usrfullname AS ClientFeeEarner
, @tempDesc AS ClientPrimaryBusinessType
Also your stored procedure allows for SQL injection around:
SET @SQL =
'SELECT clnt_cat_desc FROM ' + @SERVERNAME +
'.' + @DBASE + '.dbo.hbl_clnt_cat WHERE inactive = ''N''
AND clnt_cat_code = ''' + @CODE + ''''
EXECUTE sp_executeSQL @SQL