Solved

Concatenate a field in a SQL statment

Posted on 2001-06-07
3
284 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 142

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 142

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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.
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now