SQL syntax problem (multiple selects)
- by user279521
I am having problems retrieving accurate data values with my stored proc query below:
    CREATE PROCEDURE usp_InvoiceErrorLog
    @RecID int
AS
DECLARE @ErrorString as varchar(1000),
        @ErrorCode as int;
Select @ErrorCode = ErrorCode from tbl_AcctRecv_WebRpt Where RecID = @RecID;
IF NOT(@ErrorCode = NULL)
    Begin
        Select @ErrorString = ErrorDesc from tbl_ErrDesc Where ErrorCode = @ErrorCode
    End
Select  RecID, VendorNum, VendorName, InvNum, InvTotal, (SELECT CONVERT(VARCHAR(11), InvDate, 106) AS [DD MON YYYY]) As InvDate,
        TicketRequestor, ErrorCode, @ErrorString as ErrorDesc
    from tbl_AcctRecv_WebRpt Where RecID =  @RecID
The ErrorDesc column (in the final select statement at the bottom) returns a NULL value, when it should return a valid string data.
Any ideas?