Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have one sql queries.i want to retrieve hour and minutes. As per client requirement,i want to add display like this.

Ex--its retrieving like this(1281.5270). it should retrieve as 1281.275(means it should add 5+270=275). i have one sql quiries--

SQL
select (cast(Sum(IsNull(Effort1,0))as varchar(50))+''+ cast(Sum(IsNull(Effort1Minutes,0))as varchar(50))) as Total1,
          (cast(Sum(IsNull(Effort2,0))as varchar(50))+''+ cast(Sum(IsNull(Effort2Minutes,0))as varchar(50))) as Total2,
           (cast(Sum(IsNull(Effort3,0))as varchar(50))+''+ cast(Sum(IsNull(Effort3Minutes,0))as varchar(50))) as Total3,
            (cast(Sum(IsNull(Effort4,0))as varchar(50))+''+ cast(Sum(IsNull(Effort4Minutes,0))as varchar(50))) as Total4,
             (cast(Sum(IsNull(Effort5,0))as varchar(50))+''+ cast(Sum(IsNull(Effort5Minutes,0))as varchar(50))) as Total5,
              (cast(Sum(IsNull(Effort6,0))as varchar(50))+''+ cast(Sum(IsNull(Effort6Minutes,0))as varchar(50))) as Total6,
               (cast(Sum(IsNull(Effort7,0))as varchar(50))+''+ cast(Sum(IsNull(Effort7Minutes,0))as varchar(50))) as Total7

    FROM TimeSheetDetail


whenever i am running this above quiries.i am getting 1281.5270(this one just only concatination). now i want to display like this(1281.275)

how i will add this ? pls reply me
Posted
Updated 30-Oct-13 20:09pm
v2
Comments
coded007 31-Oct-13 2:43am    
you are converting it into varchar string format. Please don't to that. remove cast and try it
Mike Meinz 31-Oct-13 9:49am    
So are you saying that the first SUM() returns 1281.5 and the second SUM() returns 270 and you want the result of those two SUM() functions put together so that the result it 1281.275?

If so, that does not make sense. That would be equivalent of the following:
  1281.005
+0000.270
  ---------
1281.275

Use IMPROVE QUESTION link above and please explain in more detail.

1 solution

Your database should not do this. If you want to enforce a certain number of decimals, or whatever, your presentation layer should do this. Your data itself should not be truncated, it should remain the real value.

And yes, your SQL is a nightmare. Get rid of the varchar casts. How can 16 casts to varchar(50) give you a four digit number either side of the decimal ? Also, why on earth are you concatenating empty strings ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900