Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 17th, 2005, 04:08 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Computing a value

I'm wondering if someone knows how to do this.

I am trying to add a sum of to two values within a column. I know it's easy but for some reason I can't this to function properly so I can use this value in Crystal.

I'm trying to add hudnumber 801 and 808 which are Broker Fee 1 and Broker Fee 2 in my case stmt. I'm trying to add their fees but I can't seem to get the syntax right. Here is the code:

SELECT DISTINCT
loan_main.loanid,
loan_query.cmlastname + ',' + loan_query.cmfirstname AS 'Borrower Name',
loan_main.totalloanamount,
loan_main.loanrate AS 'Int. Rate',
setups_businesschannels.channelalias AS 'Business Channel',
loan_main.businesschannelid,
custom_loanmain.Type4DisburseDT,
loan_main.dateofdisclosure,
loan_main.actualclosingdate,
loan_postclosing.disbursementdate,
loan_query.lsstatusalias,
loan_query.pmstate,
--loan_funding_detail.[description] AS 'Fee Description',
Case hudnumber
When 809 Then 'YSP'
When 811 Then 'Admin Fee'
When 813 Then 'Appraisal'
When 814 Then 'Credit Report'
When 801 Then 'Broker Fee 1' -
When 808 Then 'Broker Fee 2' - I'm trying to add these two description fee amounts
End As Fees,
loan_funding_detail.fundamount AS 'Fee Amount',
loan_funding_detail.hudamount,
re.name AS 'Broker'



FROM loan_main
INNER Join loan_channelentities lce ON loan_main.lenderdatabaseid = lce.entitylenderdatabaseid AND loan_main.loanrecordid = lce.loanrecordid

INNER JOIN rolodex_entity re ON lce.lenderdatabaseid = re.lenderdatabaseid AND lce.entityid = re.entityid AND (lce.entitycategoryid = 66 OR
lce.entitycategoryid = 67)

INNER JOIN loan_query ON loan_main.lenderdatabaseid = loan_query.lenderdatabaseid AND
loan_main.loanrecordid = loan_query.loanrecordid AND
loan_main.statusid = loan_query.lsstatusid
INNER JOIN loan_postclosing ON loan_main.lenderdatabaseid = loan_postclosing.lenderdatabaseid
AND loan_main.loanrecordid = loan_postclosing.loanrecordid
INNER JOIN custom_loanmain ON loan_main.lenderdatabaseid = custom_loanmain.lenderdatabaseid
AND loan_main.loanrecordid = custom_loanmain.loanrecordid

INNER JOIN loan_funding ON loan_main.loanrecordid = loan_funding.loanrecordid

INNER JOIN loan_funding_detail ON loan_funding_detail.loanrecordid = loan_funding.loanrecordid
AND loan_funding.sequencenumber = loan_funding_detail.sequencenumber

INNER JOIN setups_businesschannels ON loan_main.businesschannelid = setups_businesschannels.channelid


WHERE ((loan_main.businesschannelid = 8) OR (loan_main.businesschannelid = 2)
OR (loan_main.businesschannelid = 7 ))
AND loan_funding_detail.hudnumber in (801, 808, 809, 811, 813, 814)

order by setups_businesschannels.channelalias

Reply With Quote
  #2  
Old March 17th, 2005, 05:35 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
You want add the values of Broker Fee 1 column and Broker Fee 2 column?

Something like this??
Code:
Case hudnumber
   WHEN 801 THEN BrokerFee1 + BrokerFee2,
   WHEN 808 THEN BrokerFee1 + BrokerFee2
END As 'Fees'

Reply With Quote
  #3  
Old March 17th, 2005, 05:38 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Maybe I misunderstanding but isn't that concatenating the string?

Reply With Quote
  #4  
Old March 17th, 2005, 05:40 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I want to add the values of Broker Fee 1 and Broker Fee 2 - fund amounts.

Reply With Quote
  #5  
Old March 17th, 2005, 05:47 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
It only concatenates a string if the data types are strings, otherwise if the data types are a numeric value, it adds them together.

Reply With Quote
  #6  
Old March 17th, 2005, 05:48 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Is there something like

Case
hudnumber = 801 Then BrokerFeeAmt = hudfundamount.801 + hudfundamount.808
End

?

Reply With Quote
  #7  
Old March 17th, 2005, 05:50 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Is hudfundamount.801 a column name??

Reply With Quote
  #8  
Old March 17th, 2005, 05:51 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Provide me an example of the column names and some sample data, and I try to write something for you, but be quick, I'm leaving soon.

Reply With Quote
  #9  
Old March 17th, 2005, 05:51 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Quote:
Originally Posted by Memnoch
It only concatenates a string if the data types are strings, otherwise if the data types are a numeric value, it adds them together.


801 and 808 are numbers but when I do that is concates the string Broker Fee 1 + Broker Fee 2, it doesn't add the amount.

The fields are the following, the two that I want to add:

Fees Fee Amount
Broker Fee 1 1000.00
Broker Fee 2 500.00

I want to combine these two fields

Reply With Quote
  #10  
Old March 17th, 2005, 05:58 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
That is because you have enclosed the field names in quotes, which designates them as a string.
So you aren't adding the values of the fields, you are concatenating the string values 'Broker Fee 1' and 'Broker Fee 2'
Code:
WHEN 801 THEN 'Broker Fee 1' 

My example above should work, you may need to denote the table the column is in.

Example:
Code:
Case hudnumber
   WHEN 801 THEN Table1.BrokerFee1 + Table1.BrokerFee2,
   WHEN 808 THEN Table1.BrokerFee1 + Table1.BrokerFee2
END As 'Fees'

Reply With Quote
  #11  
Old March 17th, 2005, 06:11 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Thanks but it didn't work. I'll keep trying.

Reply With Quote
  #12  
Old March 17th, 2005, 06:16 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I see where I am miscommunicating,

The two rows that I am trying to combine are Broker Fee 1 and Broker Fee 2. The column that the values of these two rows are in the Fee Amount column.

Fees Fee Amount
Broker Fee 1 1000.00
Broker Fee 2 500.00

So the desire results would be Broker Fee 1 + Broker Fee 2 As 'Broker Fee'

Fees Fee Amount
Broker Fee 1500.00 -> adding the fee amounts of Broker Fee 1 and Broker Fee 2

Reply With Quote
  #13  
Old March 18th, 2005, 08:56 AM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I want to see if providing a more detailed result set may help:

Loan# Fee Fee Amount
3246 Admin Fee 175.0
3246 Broker Fee 1 2100.0 These are the two records that I need to combine.
3246 Broker Fee 2 575.0

The Desired Result Set:

Loan# Fee Fee Amount
3246 Admin Fee 175.0
3246 Broker Fee 2675.0

Reply With Quote
  #14  
Old March 18th, 2005, 09:33 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
I'm not sure your result can actually be calculated like that within the query.

If BrokerFee1 & BrokerFee2 were columns then you could, but the column is FeeAmount, and there isn't any way of determining which FeeAmount values to calculate.

Reply With Quote
  #15  
Old March 18th, 2005, 10:00 AM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
Ok thanks. I'll think of something or maybe the user will just have to view them as separate fields if it cannot be done.


Thanks for all of your help.

Reply With Quote