Solved

sql 2005 query

Posted on 2008-06-16
3
182 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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now