×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SQL Query for formatting money

SQL Query for formatting money

SQL Query for formatting money

(OP)
I am just a beginner with SQL. I have two queries which were previously set up. The first formats dollars and cents, however the second one does not. I want to know if I can insert the Convert statement into the second query in the appropriate place?

Correct value for money in one query:
select Convert(nvarchar(max),cast(sum(Attainment) as money),1) as Cp_Comm, 'Year To Date Revenue' as Payee_id from payout_calc where incentive_id in ('Equipment Sales','SalesRep Service Commission','Field Service','Test Bench ELECTRICAL','Test Bench OTHER') and convert(nvarchar,Calc_Plan_Yr)='{!CurrentYearQC}' and payee_id<>'Jesse Flores'

Incorrect value as money in another query below:
Select C.Period_number AS Month,sum(Attainment) as [Total Revenue] from Payout_calc T Join Calendar_detail C On T.Period_Number=C.Period_number where incentive_id in ('Equipment Sales','SalesRep Service Commission','Field Service','Test Bench ELECTRICAL','Test Bench OTHER') and payee_id<>'Jesse Flores' Group By C.Period_number order by Month

Can I insert the sql convert statement into the query as below or is that not where it goes?
Select C.Period_number AS Month, select Convert(nvarchar(max),cast sum(Attainment)as money),1) as [Total Revenue] from Payout_calc T Join Calendar_detail C On T.Period_Number=C.Period_number where incentive_id in ('Equipment Sales','SalesRep Service Commission','Field Service','Test Bench ELECTRICAL','Test Bench OTHER') and payee_id<>'Jesse Flores' Group By C.Period_number order by Month

RE: SQL Query for formatting money

Omit the second "select":

Select C.Period_number AS Month, Convert(nvarchar(max),cast sum(Attainment)as money),1) as [Total Revenue] 
from Payout_calc T Join Calendar_detail C On T.Period_Number=C.Period_number 
where incentive_id in ('Equipment Sales','SalesRep Service Commission','Field Service','Test Bench ELECTRICAL','Test Bench OTHER') 
and payee_id<>'Jesse Flores' Group By C.Period_number order by Month
 

RE: SQL Query for formatting money

(OP)
For some reason I get an error near sum when using the query editor.

RE: SQL Query for formatting money

When you run it, what error do you get?

Tamar

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close