| Author |
Topic |
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2008-12-17 : 06:01:59
|
| Hi,got abit of a data issue, but need to get sums off few figures on the tables I have.cust_id, grading001, 065001, A001, 067002, abc002, 115I tried case(sum(grading) > 0) then sum(grading) else grading, but I get grading is not in group clause etc.Any tips on parsing strings etc? |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-17 : 06:10:05
|
| select sum(grading)as sumn,grading into sampletable from urtable group by gradingselect case when sumn > 5 then sumn else grading end from sampletabletake the sum in another table try this once |
 |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2008-12-17 : 06:13:00
|
Ok I can take the grading into a sample table but how would i eliminate the characters and just leave the integers?quote: Originally posted by bklr select sum(grading)as sumn,grading into sampletable from urtable group by gradingselect case when sumn > 5 then sumn else grading end from sampletabletake the sum in another table try this once
|
 |
|
|
umertahir
Posting Yak Master
154 Posts |
Posted - 2008-12-17 : 06:20:02
|
Can't you try ISNUMERIC() function to check if the number is integer only then do the sum?quote: Originally posted by cipriani1984 Ok I can take the grading into a sample table but how would i eliminate the characters and just leave the integers?quote: Originally posted by bklr select sum(grading)as sumn,grading into sampletable from urtable group by gradingselect case when sumn > 5 then sumn else grading end from sampletabletake the sum in another table try this once
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:23:48
|
quote: Originally posted by umertahir Can't you try ISNUMERIC() function to check if the number is integer only then do the sum?quote: Originally posted by cipriani1984 Ok I can take the grading into a sample table but how would i eliminate the characters and just leave the integers?quote: Originally posted by bklr select sum(grading)as sumn,grading into sampletable from urtable group by gradingselect case when sumn > 5 then sumn else grading end from sampletabletake the sum in another table try this once
ISNUMERIC is not always reliable try thisSELECT ISNUMERIC('3e2'),ISNUMERIC('4d5') |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2008-12-17 : 06:28:11
|
I triedSUM(ISNUMERIC(grading)) and it gave me really low figures that dont add up correctly?quote: Originally posted by umertahir Can't you try ISNUMERIC() function to check if the number is integer only then do the sum?quote: Originally posted by cipriani1984 Ok I can take the grading into a sample table but how would i eliminate the characters and just leave the integers?quote: Originally posted by bklr select sum(grading)as sumn,grading into sampletable from urtable group by gradingselect case when sumn > 5 then sumn else grading end from sampletabletake the sum in another table try this once
|
 |
|
|
umertahir
Posting Yak Master
154 Posts |
Posted - 2008-12-17 : 06:31:03
|
You would need to add CASE statement using ISNUMERICquote: ISNUMERIC is not always reliable try thisSELECT ISNUMERIC('3e2'),ISNUMERIC('4d5')
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:36:07
|
quote: Originally posted by umertahir You would need to add CASE statement using ISNUMERICquote: ISNUMERIC is not always reliable try thisSELECT ISNUMERIC('3e2'),ISNUMERIC('4d5')
?? what do mean by that? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:37:29
|
quote: Originally posted by cipriani1984 I triedSUM(ISNUMERIC(grading)) and it gave me really low figures that dont add up correctly?
it should be SUM(CASE WHEN ISNUMERIC(grading)=1 AND CHARINDEX('d', grading)=0 AND CHARINDEX('e', grading)=0 THEN grading ELSE 0 END) |
 |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2008-12-17 : 06:38:22
|
I was confused by that also,I didselect distinct cust_id, sum(grading) as gradewhere ISNUMERIC(grading) > 0but I get really low 1 digit values when the values in the tables are 3 digits.Any ideas?quote: Originally posted by visakh16
quote: Originally posted by umertahir You would need to add CASE statement using ISNUMERICquote: ISNUMERIC is not always reliable try thisSELECT ISNUMERIC('3e2'),ISNUMERIC('4d5')
?? what do mean by that?
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:45:22
|
quote: Originally posted by cipriani1984 I was confused by that also,I didselect distinct cust_id, sum(grading) as gradewhere ISNUMERIC(grading) > 0but I get really low 1 digit values when the values in the tables are 3 digits.Any ideas?
what does last suggestion give u? |
 |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2008-12-17 : 06:55:55
|
worked, thanksquote: Originally posted by visakh16
quote: Originally posted by cipriani1984 I was confused by that also,I didselect distinct cust_id, sum(grading) as gradewhere ISNUMERIC(grading) > 0but I get really low 1 digit values when the values in the tables are 3 digits.Any ideas?
what does last suggestion give u?
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 06:57:51
|
welcome |
 |
|
|
|