Solved

sql 2005 query

Posted on 2008-06-16
3
184 Views
Last Modified: 2010-03-20
i have a query written when i select the query
i get the correct result
0044775019      638.42      VO      2008-06-06 00:00:00      CK      419116

but when i concetanate the query instead of 638.42 it is coming as 638.41 can any one tell me why is it happening like that my query is

and the result for that query is
D0010044775019        0000419116000006384120080606                        
SELECT  'D' + '001' + banknbr + SPACE(7)
      + ( CASE WHEN adjgdoctype = 'VC' THEN 'V'
                 ELSE ' '
            end ) + RIGHT(REPLICATE('0', 10)
                         + convert(VARCHAR(10), RTRIM(adjgrefnbr)), 10)
        + RIGHT(REPLICATE('0', 10)
              + CONVERT(varchar(10), CONVERT(int, ( CASE WHEN adjgdoctype = 'VC'
                                                          THEN 0
                                                         ELSE curyadjdamt * 100
                                                     end ))), 10)
        + REPLACE(CONVERT(VARCHAR, adjgdocdate, 102), '.', '') + SPACE(30)
        + NAME AS details
FROM #positivepay

Open in new window

0
Comment
Question by:romeiovasu
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 21798620
what is the datatype of curyadjdamt? is it is float? try to change it to numeric or decimal or try the following query


SELECT  'D' + '001' + banknbr + SPACE(7)
      + ( CASE WHEN adjgdoctype = 'VC' THEN 'V'
                 ELSE ' '
            end ) + RIGHT(REPLICATE('0', 10)
                         + convert(VARCHAR(10), RTRIM(adjgrefnbr)), 10)
        + RIGHT(REPLICATE('0', 10)
              + CONVERT(varchar(10), CONVERT(int, ( CASE WHEN adjgdoctype = 'VC'
                                                          THEN 0
                                                         ELSE convert(decimal(10,2) , curyadjdamt) * 100
                                                     end ))), 10)
        + REPLACE(CONVERT(VARCHAR, adjgdocdate, 102), '.', '') + SPACE(30)
        + NAME AS details
FROM #positivepay
0
 
LVL 2

Expert Comment

by:mayno224
ID: 21798676
there's several nested command to get the value of 'curyadjdamt'.  i suggest breaking the query down to its simplest form then add to it step by step until you find where 638.41 is being returned.  for example, start with....

select curyadjdamt * 100 from positivepay

if the above returns 63842, then add the next 'step' to the query...

CASE WHEN adjgdoctype = 'VC' THEN 0 ELSE curyadjdamt * 100

select adjgdoctype, CASE WHEN adjgdoctype = 'VC' THEN 0 ELSE curyadjdamt * 100 from positivepay

keep adding 'steps' until you find where 638.41 (or '63841') is returned.  the last step that you entered will be where the problem lies.

hope this helps!
0
 

Author Comment

by:romeiovasu
ID: 21798780
thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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