Solved

Concatenate a field in a SQL statment

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import access table (latest access version) into sql server express table 5 21
SQL Server Designer 19 39
SqlServer no dupes 25 34
SQL Update trigger 5 16
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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

786 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