• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Total from a table in sql

Hi,

I have a table called T which looks like this

TL     Amt
H        2
N        70
C        10
B        Null
S        50

I need an sql statment to show the total of Amt field for each item in this table

Please help

Thanks,

R8VI
0
R8VI
Asked:
R8VI
1 Solution
 
SreejithGCommented:
SELECT SUM(Amt) FROM T
0
 
Pratima PharandeCommented:
select TL , Sum(amt) from T
group by TL

Or
select TL , Sum(isnull(amt,0)) from T
group by TL
0
 
kamindaCommented:
Code should be this
SELECT TL, SUM(Amt) FROM T GROUP BY TL

Open in new window

0
 
malikirfan28Commented:
for each item mean for each TL?
And B TL have NULL amount. Does it STRING NULL value or DB Null value? Can you please tell what is the type of Amt column (i.e. either its varchar or decimal)?
0
 
malikirfan28Commented:
If this NULL is a db null value then you can use the following script.

select TL , Sum(isnull(amt,0)) from T
group by TL

and if it is String NULL then you can use the following script

select TL, sum(Amt) from
(select TL, case when isnumeric(Amt) = 1 then Amt else 0 end as Amt from T) as a
group by TL
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now