Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Needs Help with Creating SQL Statement
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Needs Help with Creating SQL Statement

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Needs Help with Creating SQL Statement
    Posted: 29 April 2005 at 1:45pm
Can someone please help me to create a sql statement for the following information:
 
1.) How many orders were made for an item a certain month?
2.) How many orders were made for an item in a year?


Edited by Misty - 29 April 2005 at 1:46pm
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 29 April 2005 at 2:17pm
Dim intSearchMonth, intSearchYear, intItemID

intSearchMonth = month to search
intSearchYear = year to search for
intItemID = ID for the item your searching

' SQL for items for a certain month
strSQL = "SELECT Count(ItemID) AS Ordered FROM tblOrders WHERE Month(tblOrders.Order_Date) = " & intSearchMonth & " AND tblOrders.ItemID = " & intItemID & " "


' SQL for items for a certain Year
strSQL = "SELECT Count(ItemID) AS Ordered FROM tblOrders WHERE Year(tblOrders.Order_Date) = " & intSearchYear & " AND tblOrders.ItemID = " & intItemID & " "


the above is on the idea you have a orders table holding the Item ID that was ordered. without more details we can't get it exact. hope the above help


Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 29 April 2005 at 4:47pm
The only correction I would make is that ít's probably a specific month AND year, so the month query should include the year as well.

Edited by ljamal - 30 April 2005 at 1:31am
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 29 April 2005 at 5:18pm
good point cheers for that.. heres a re write below


Dim intSearchMonth, intSearchYear, intItemID

intSearchMonth = month to search
intSearchYear = year to search for
intItemID = ID for the item your searching

' SQL for items for a certain month
strSQL = "SELECT Count(ItemID) AS Ordered FROM tblOrders WHERE Month(tblOrders.Order_Date) = " & intSearchMonth & " AND tblOrders.ItemID = " & intItemID & " AND Year(tblOrders.Order_Date) = " & intSearchYear & " "


' SQL for items for a certain Year
strSQL = "SELECT Count(ItemID) AS Ordered FROM tblOrders WHERE Year(tblOrders.Order_Date) = " & intSearchYear & " AND tblOrders.ItemID = " & intItemID & " "
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 01 May 2005 at 2:05am
Thanks for the help! I need some more help. How would I write a sql query if I had the two following tables: Customers and Web Hosting. There is a WebHostingID field in both table. Some customers may not have a web hosting ID. I'd like to show all of the customers that have either a value or no value in the WebHostingID. How do I accomplish this?
Back to Top
one-ring View Drop Down
Newbie
Newbie


Joined: 16 May 2005
Location: Philippines
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote one-ring Quote  Post ReplyReply Direct Link To This Post Posted: 16 May 2005 at 10:27pm
Hi Misty!

i'm not sure if you still need answer to your last query but just the same, here is my suggestion:

if you want to know all the customers that have web hosting record, try this:

select C.*
from CUSTOMERS as C
inner join WEBHOSTING as WH on C.webhostingid = WH.webhostingid
if you want to know all the customers that have no web hosting record, try this:
select C.*
from CUSTOMERS as C
left outer join WEBHOSTING as WH on C.webhostingid = WH.webhostingid
where WH.webhostingid is null
Hope this helps Smile

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.