Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Concatenate a field in a SQL statment

Posted on 2001-06-07
3
Medium Priority
?
303 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 400 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

876 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