Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sub total

Author  Topic 

papershop
Starting Member

27 Posts

Posted - 2011-08-11 : 05:44:37
dear all

i have sintax : ...

select line, familyname, isnull([1],0) as Jan ,isnull([2],0) as Feb ,isnull([3],0) as Mar,isnull([1],0)+isnull([2],0)+isnull([3],0) as Q1,
isnull([4],0) as Apr, isnull([5],0) as Mei, isnull([6],0) as Jun, isnull([4],0)+isnull([5],0)+isnull([6],0) as Q2,
isnull([7],0) as Jul,isnull(,0) as Aug,isnull([9],0) as Sep,isnull([7],0)+isnull(,0)+isnull([9],0) as Q3,
isnull([10],0) as Okt, isnull([11],0) as Nov, isnull([12],0) as Dec, isnull([10],0)+isnull([11],0)+isnull([12],0) as Q4
from (
select line,_month, familyname, valuenet from dbo.v_fact_sales
WHERE (_Year = YEAR(GETDATE())-1))up
pivot (sum(valuenet) for _month in ([1],[2],[3],[4],[5],[6],[7],,[9],[10],[11],[12]) )as pvt
order by line


and with this sintax i have data :

line product sales Jan sales Feb sales Mar
AI fgl 763660298 695205829 975460094
AI sf 1457229486 1842005461 1484741422
AI ds 1663809803 1200154719 1726119190
AI sd 146921335 110756898 134292994
AI we 295428173 238081171 359766957
AI fdas 847919896 772739367 974749461
C1 ew 3393074019 2657642701 3401683963
C1 cv 196044717 421898144 358896980
C1 s 76360038 89527464 96316303
C1 dd 107493696 93201840 119578032
C1 sdf 781488479 770760549 937287297
C2 sdf 0 0 0
C2 sf 143887226 199108783 254632999
C2 sadf 7230148602 5181272359 6800802345


what should i do..in my sintax if i want to add sub total by line?

help me please


@papershop

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-11 : 08:23:05
isnt it matter of adding all the values.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-08-11 : 19:51:07
Every SQL forum or newsgroup expects that you will post DDL, sample data and clear specifications which might might include output. This is explained in the FAQ section. We can not read minds; what would we need to know to do your job for you?

Tables must have keys and should have DRI, constraints, and all the basic features of a schema. You should know use ISO-8601 Standards for temporal data, avoid needless dialect, basic data modeling and use ISO-11179 Standards for data element names. Please tell us if you can change the DDL.

What you posted is not even normalized!

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-08-12 : 00:06:38
Celko. Go away. You have nothing constructive to offer. If I was admin on this site, you'd be banned. Tell ya what...I AM an admin on SQL Mag. Post this crap there and I'll ban you in an instant.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-12 : 03:57:57
quote:
what should i do..in my sintax if i want to add sub total by line?

Please show us how is the expected result looks like


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -