SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL WITH CUBE Question
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Luijo
Starting Member

USA
5 Posts

Posted - 03/29/2013 :  18:59:01  Show Profile  Reply with Quote
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.



Edited by - Luijo on 03/30/2013 16:09:41

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/30/2013 :  01:54:02  Show Profile  Reply with Quote
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

USA
5 Posts

Posted - 03/30/2013 :  10:59:49  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/31/2013 :  02:57:05  Show Profile  Reply with Quote
welcome

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

Go to Top of Page

Luijo
Starting Member

USA
5 Posts

Posted - 03/31/2013 :  10:20:26  Show Profile  Reply with Quote
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

USA
5 Posts

Posted - 03/31/2013 :  10:25:08  Show Profile  Reply with Quote
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)

Edited by - Luijo on 03/31/2013 14:35:24
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 04/01/2013 :  00:15:08  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 04/01/2013 :  00:20:01  Show Profile  Reply with Quote
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

USA
5 Posts

Posted - 04/01/2013 :  11:09:06  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 04/01/2013 :  11:43:01  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000