Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

concatenating and two decimal places

 
   Database Help (Home) -> Programming RSS
Next:  Next Meeting -Tuesday May 25 - Virtual Webcast on..  
Author Message
SQL Programmer

External


Since: Jun 17, 2008
Posts: 48



(Msg. 1) Posted: Sun May 23, 2010 7:37 pm
Post subject: concatenating and two decimal places
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hello:

Below is my query, and I need help with two things.

First, I am trying to get each field in this query to be concatenated
together. But, there is a space between the field "CMTrxNum" and "CASE WHEN
TRXAMNT....". How do I get rid of this spacing?

Secondly, I need for the two fields that contain the phrases
"CAST(-1*TRXAMNT as varchar)" and "CAST(TRXAMNT as varchar)" to be two
decimal places. How do I do this?

select '2000038028654' + '0000' + CMTrxNum + CASE WHEN TRXAMNT <0 THEN
CAST(-1 * TRXAMNT as varchar)
ELSE CAST(TRXAMNT as varchar) END
+ convert(varchar, TRXDATE, 112)
+ CASE WHEN VOIDED = '1' then 'V' ELSE '' END
from CM20200
where CHEKBKID = 'UPTOWN TRUST' and SOURCDOC = 'PMPAY' or SOURCDOC = 'PMCHK'

SQL Programmer (it's just a name)

 >> Stay informed about: concatenating and two decimal places 
Back to top
Login to vote
Plamen Ratchev

External


Since: Aug 20, 2008
Posts: 672



(Msg. 2) Posted: Sun May 23, 2010 11:06 pm
Post subject: Re: concatenating and two decimal places [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

It is good practice to always specify the VARCHAR length. Try this:

SELECT '2000038028654' + '0000' + CMTrxNum +
CASE WHEN TRXAMNT < 0 THEN LTRIM(STR(-1 * TRXAMNT, 20, 2))
ELSE LTRIM(STR(TRXAMNT, 20, 2))
END + CONVERT(VARCHAR(Cool, TRXDATE, 112) +
CASE WHEN VOIDED = '1' THEN 'V' ELSE '' END
FROM CM20200
WHERE CHEKBKID = 'UPTOWN TRUST'
AND SOURCDOC IN ('PMPAY', 'PMCHK');

--
Plamen Ratchev
http://www.SQLStudio.com

 >> Stay informed about: concatenating and two decimal places 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Decimal Comma vs Decimal Point - Hello, I want to insert a Single/Float type value into a table using the following SQL statement. I'm executing this from a VB6 app using ADO 2.7. myValue = "0.5074655" (Entered by the user into a textbox) strSQL = "INSERT INTO myTable ...

Concatenating column values - How can I concatenate column values (not row values) in Transact-SQL? Thanks. Pere.

concatenating column values without a cursor? - Some time ago, someone in here showed me this type of code for concatenating column values together. I've used it in cursors and it works fine. DECLARE @Kids VARCHAR(1000) SELECT @Kids = COALESCE(@Kids + ', ', '') + KidName FROM CustKids..

Concatenating rows with carriage return - I have a table containing unit and employees assigned Unit Employee 2 North Michael Gates 2 North Bill Jordan 3 South Wendy Shore I want to write a query that will concatenate all the employees that....

How to concatenating from rows into string with delimited .. - as subject
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]