tags:

views:

96

answers:

1
IF RTRIM(@GLDD_LEDGER_CODE)= '00' 
BEGIN 
 SELECT @SYS_REM =GLMA_ACCT_NAME  
 FROM  GLAS_GL_MASTERS 
 WHERE  GLMA_COMP_CODE  = @COMP_CODE
  AND GLMA_LDGR_CODE  = '00'
  AND GLMA_DEPT_NO  = SUBSTRING(@GLDD_ACCT_CODE, 2, 2)
  AND GLMA_ACCT_CODE  = SUBSTRING(@GLDD_ACCT_CODE, 4, 4)
  AND GLMA_YEAR  = DATEPART(YYYY, GETDATE())
END

ELSE
BEGIN 
 SELECT @SYS_REM = A.COAD_PTY_FULL_NAME AS NAME
 FROM  GLAS_PTY_ADDRESS A,
   GLAS_SBLGR_MASTERS B 
 WHERE  A.COAD_COMP_CODE  = @COMP_CODE
  AND A.COAD_COMP_CODE  = B.SLMA_COMP_CODE
  AND A.COAD_ADDR_ID  = B.SLMA_ADDR_ID
  AND B.SLMA_LDGRCTL_CODE  = @GLDD_LEDGER_CODE
  AND B.SLMA_LDGRCTL_YEAR  = DATEPART(YYYY, GETDATE())
  AND B.SLMA_STATUS  = 'A'
  AND B.SLMA_ACNO  = @GLDD_ACCT_CODE  
END

How can I set alias name for both select statement for selecting the name?

A: 

How can I set alias name for both select statement for selecting the name?

You can't because you are storing it in a variable.

Either use an OUTPUT parameter (if this code is in a stored procedure) or

SELECT @SYS_REM AS MyName

to return it as a result set

Kristen