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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL WITH CUBE Question

Author  Topic 

Luijo
Starting Member

5 Posts

Posted - 2013-03-29 : 18:59:01
Hi everyone, I`m new at this forums, hoping somebody can help me with this question, Thanks:

Write a summary query WITH CUBE that returns LineltemSum (which is the sum of
lnvoiceLineltemAmount) grouped by Account (an alias for AccountDescription) and State (an alias for
VendorState). Use the CASE and GROUPING function to substitute the literal value "*AIL*" for the
summary rows with null values.


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-30 : 01:54:02
look up for syntax of WITH CUBE in books online and try. post if you face any issues in it. Otherwise we wont help with assignment questions.

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

Go to Top of Page

Luijo
Starting Member

5 Posts

Posted - 2013-03-30 : 10:59:49
Thanks a lot Visakhm, I will.
quote:
Originally posted by visakh16

look up for syntax of WITH CUBE in books online and try. post if you face any issues in it. Otherwise we wont help with assignment questions.

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



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-31 : 02:57:05
welcome

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

Go to Top of Page

Luijo
Starting Member

5 Posts

Posted - 2013-03-31 : 10:20:26
so far this is what I got, but something is not right:

SELECT SUM(InvoiceLineItemAmount) AS LineItemSum
, CASE
WHEN GROUPING(VendorState) = 1 THEN '*ALL*'
ELSE VendorState END State
FROM Vendors
, InvoiceLineItems
, GLAccounts
, Invoices
WHERE Vendors.VendorID = Invoices.VendorID
AND Invoices.InvoiceID = InvoiceLineItems.InvoiceID
AND GLAccounts.AccountNo = InvoiceLineItems.AccountNo
GROUP BY AccountDescription, VendorState WITH CUBE
Go to Top of Page

Luijo
Starting Member

5 Posts

Posted - 2013-03-31 : 10:25:08
also I need some help in this one too:
I need to figuer it out which one is correct, if I want to return invoices due before the last day of the current month?

WHERE InvoiceDueDate <= dateadd(month, datediff(month, 0, getdate()) + 1, -1)

WHERE InvoiceDueDate < dateadd(month, datediff(month, 0, getdate()) + 1, 0)
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-01 : 00:15:08
second is the correct approach.....
WHERE InvoiceDueDate < dateadd(month, datediff(month, 0, getdate()) + 1, 0)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-01 : 00:20:01
understand the logic first. then you will be able to determine it yourselves

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Luijo
Starting Member

5 Posts

Posted - 2013-04-01 : 11:09:06
Hi Visakh16, I really appreciated your help, I`m glad that there are still people willing to help others.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-01 : 11:43:01
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -