Solved

Concatenate a field in a SQL statment

Posted on 2001-06-07
3
287 Views
Last Modified: 2008-02-20
Is there a way to concatenate a field in a SQL statment, in a Stored Procedure, and use the the alias some place else in the same stored procedure.  In the below, I know that I can't use 'Amount_Paying', I must use another case statment.  Is there a way around using a 2nd case statement.  I know I can create a temp table, but I would like to just refer to the alias in the same SQL statment.

Thanks in advance for any help
LJG


SELECT  tbl_za_Deposit_Start.Deposit_Number,
     Amount_Paying =
        Case
                          When tbl_za_Deposit_Start.Amount_Partial_Paying>0 then 0            
                         else tbl_za_Deposit_Start.Amount_Owed + tbl_za_Deposit_Start.New_Adjustment
                     end,      

                  Amount_Paying + tbl_za_Deposit_Start.P_Pay AS Tot

     FROM tbl_za_Deposit_Start
     WHERE tbl_za_Deposit_Start.Paying = 1  
0
Comment
Question by:LJG
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 6164016
SELECT
  Deposit_Number,
  Amount_Paying,
  Amount_Paying + P_Pay AS Tot
FROM (
SELECT  
  Deposit_Number,
  P_Pay,
  Amount_Paying = Case
          When Amount_Partial_Paying>0 then 0
          else Amount_Owed + New_Adjustment
             end
    FROM tbl_za_Deposit_Start
    WHERE Paying = 1 ) AS L

Cheers
0
 
LVL 2

Author Comment

by:LJG
ID: 6164239
Angel
As in the past you have the to the point answer.  You always make my life easier when you answer my questions.  I increased the points because it solved my problem exactly the way I wanted it solved.

Thanks Again
LJG
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6164256
:-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question