I have a table that is recording hits to a website. Everytime someone views a page, the datetime of the hit is recorded in a field called hit_date_time. I would like to be able to come up with a query that will show how many hits occured on a given day or given days, broken down by hour.
The resulting table for two days would look something like: Time Hits 1/1/01 12:00 1 1/1/01 1:00 23 1/1/01 2:00 54 1/2/01 1:00 15 1/2/01 2:00 14
I can't seem to figure out how to write the query so that I can take into consideration the date and hour of the event so that I can count it.
Hello all, have a temp table where I put data from a shopping cart. I need to take the data from this temp table and put it into an orders table and an orderItems table. The table structure is as follows: The cstb_orders.orderId has a one to many relationship with the cstb_orderItems.orderId cstb_orderItemsTemp id --pk invtId descr location quantity username shiptoaddress shiptocity shiptostate shiptozip shiptophone shiptofax cstb_orders orderId --pk username shiptoaddress shiptocity shiptostate shiptozip shiptocity shiptostate shiptozip shiptophone orderdate --auto date shipdate --null cstb_orderItems id --pk orderId --fk invtId descr location quantity What is the best way to accomplish this?
Hi There i have two windows 2000 servers which are both running SQL and i would like to restore a backup from one server to the other. Which in my opinion should be an easy task but when i go into the restore option and point it at the file i would like to restore i get the follwoing error
"The database you are attempting to restore was backed up under a different sort order ID (52) than the one you are currently using on this server (50) and at least one of them is a non binary sort order. Backup or restore operation operation terminating abnormally."
The server that i am trying to restore to already has databases on this so i cannot just reinstall SQL and change the sort order not that id know how to do that but this is what i have read.
Is htere anyway that i can put insome script for the database to fix this ???
Am new in SQL server. i use SQL server 2003 ans am trying to retieve the last three orders made. Can you please help me with my Select statement so that it will only select the last three coz @ the moment it selects everything
CODE: SELECT dbo.Invoice.InvoiceNo, dbo.Sales.UnitsSold, dbo.Sales.QuantitySold, dbo.Sales.CostAmount, dbo.Item.ItemCode, dbo.Item.ItemDescription, dbo.Item.Item, dbo.PurchaseOrder.OrderNumber, dbo.PurchaseOrder.OrderDate, dbo.PurchaseOrder.OrderStatus, dbo.PurchaseOrder.QuantityOrdered, dbo.PurchaseOrder.QuantityReceived, dbo.Customer.CustomerCode FROM dbo.Invoice INNER JOIN dbo.Sales ON dbo.Invoice.InvoiceKey = dbo.Sales.InvoiceKey INNER JOIN dbo.Item ON dbo.Sales.ItemKey = dbo.Item.ItemKey INNER JOIN dbo.PurchaseOrder ON dbo.Sales.VendorKey = dbo.PurchaseOrder.VendorKey INNER JOIN dbo.Customer ON dbo.Sales.CustomerKey = dbo.Customer.CustomerKey
I'm suppose to List all orders where there is no shippedDate (just give their orderNumbers).
I have this: select orderNumber from orders where shippedDate= null;
I'm not sure what to put in place of the "= null" as that is clearly wrong
(Note: If I use "select orderNumber from orders where shippedDate;" it prints out all the orders, but I only want the orders where there are no ShippedDate...
I am trying to Invoice all of the records in my 'Orders' table. After each of the records has been invoiced I would like SQL to flag that record as having been completed so that when I run my query the next day it will ignore those having been completed already. Any feedback would be greatly appreciated.
This is the query I wrote to invoice one Order at a time by specifying each Order_Num seperately. As you can tell...I'm a n00b. Thanks all.
select convert(varchar, getdate(), 107) as Date select order_num as 'Invoice No.' from orders where order_num = '20009' select c.cust_name as Customer, c.cust_address as 'Street Address', c.cust_city as City, c.cust_state as State, c.cust_zip as 'Zip Code' from customers as c, orders as o where c.cust_id = o.cust_id and order_num = '20009' select oi.order_item as 'Line Item', oi.quantity as QTY, p.prod_name as 'Product Name', oi.item_price as 'Sale Price', oi.quantity*oi.item_price as Total from orderitems as oi, products as p where oi.prod_id = p.prod_id and order_num = '20009' order by oi.order_item select sum(quantity*item_price) as Subtotal, sum(quantity*item_price*.089) as 'Tax 8.9%', sum(quantity*item_price)+ sum(quantity*item_price*.089) as Total from orderitems where order_num = '20009'
I am trying to link my ORDERS table to my CUSTOMERS table. The Primary key in the CUSTOMERS table is a UNIQUEIDENT. The foreign key it is linking to is an INT.
When I run a query in ACCESS, it says type mismatch....
I have two tables customers and orders. customerID is the foreign key for order table. If I pass customername I need to get information about each customer how many orders holding?
Hello all- Maybe someone has some insight on this... I currently have some hash values (SHA512 through Enterprise Library) that I'm trying to compare to data in our database. When I sort the values on the pipeline (DT_STR, 1252) with a Sort and compare them against values coming out of an OLE DB Source (SQL_Latin_1_General_CP1_CI_AS) with a Merge Join, any hash that has a '/' in it is treated as inequal to the one in the database.
For even more fun, when I change the sort/merge join to a Lookup, everything (seems) to check out. Is the 1252 code page not the same as SQL_Latin_1_General_CP1_CI_AS? Any other reasons this might be happening?
I have a table with orders and customer info. I want to retrieve only customers with new orders only. These are the available fields: customer Id, Order Id, Order Date, and Order Subtotal. I need help with the "where" section of the query.
I am using a stored procedure that is databound to a dropdownlist. The stored procedure works fine, aside from the fact that the ORDER BY only sorts the list of items using the first character in the cell. E.g. The numbers 1, 20, 100 and 200 would be ordered as follows:
1
100
20
200
clearly i am doing something wrong and i apologise if it is a stupid question, but could anyone please offer me some help?
Just wanted to check. I've got a SQL 7.0 box on NT4 with about 40 databases (each about 500Mb-1Gb) which I want to move to SQL2000.
The main problem is, the 7.0 box was built with a sort order not officially supported by the finance software that uses the databases, so I want to build the SQL2000 box with the default sort orders and character sets.
I've done this in a test environment by copying the .mdf files accross and attaching them to the SQL2000 box, and this all seems to work. But is this advisable, and will there be any problems?
How to get the result for current date orders but I can get the query working for due date. " SalesOrder.DateEntered, SalesLine.OrderQuantity, (SalesLine.OrderQuantity*SalesLine.SellingPrice / SalesOrder.ExchangeRate) AS Value, (SalesLine.SellingPrice / SalesOrder.ExchangeRate) AS Price FROM Company INNER JOIN CustomerAccount ON Company.CompanyID = CustomerAccount.CompanyID INNER JOIN SalesOrder ON CustomerAccount.CustomerAccountID = SalesOrder.CustomerAccountID INNER JOIN SalesLine ON SalesOrder.SalesOrderID = SalesLine.SalesOrderID WHERE (SalesOrder.DateEntered = { fn CURDATE() }) " How could I get the current date orders?
I'm wanting to get the average number of days between orders in my orders tbl - so I've done a search and found the following sql coded that I have modified for my db tbl's and columns. But when I try and parse it - I get 'Incorrect syntax new the keyword Group' - what am I missing.
SELECT custId, AVG(invDate - priorDate) FROM(SELECT custId,invDate,LAG(invDate) OVER (PARTITION BY custId ORDER BY invDate)as priorDate FROM orders) Group BY custId
Im using Access and have created a query which adds up the grand totals of clients orders. However i want to be able to add up what each client has spent in total over any given time period. Basically in SQL logic terms:
take all order totals from same client and add together order totals to produce a grand client spend total.
I'm trying to create a couple of reports and I'm having trouble coming up with a way to do what I need to do. I already have several SQL views that I use for other reports, and they are geared toward either order-based or product-based reporting. For order-based reporting, I'm grouping the detail order lines by the order number. For product-based reporting, I'm not worrying about the order numbers necessarily. Here's my problem. I need to report on orders that have a particular product line in them (the product codes in this case start with the same letter, unique from other product lines), and separate the dollars coming from that product line and what sold with it. Something like:
Orders sold with these (A) products in them: Aproduct1 total orders $1000, $600 of which was Aproduct1 and $400 of which was Bproduct1 and Bproduct2 Aproduct2 total orders $500, $500 of which was Aproduct2 Aproduct3 total orders $700, $400 of which was Aproduct3 and $300 of which was Cproduct4 etc.
The data looks like this: (Order#) 12345 (ProductCode) Aproduct1 (quantity) 1 (dollars) $200 12345 Bproduct1 1 $100 12348 Cproduct2 2 $500 12350 Aproduct2 1 $500 12350 Cproduct1 1 $50 12350 Bproduct2 1 $300 etc.
So I'd need to pick out orders 12345 and 12350 and separate the dollars. The thing is the three products in 12350 don't know about each other.
Other than the error log is there an easy way to find the sort order and chracter set of an installed SQL Server. Also after finding the numbers is there a good reference to tell you what these numbers mean. Thanks
I have a column named "LIST" in a table with strings like the following:151231-1002-02-1001151231-1001-02-1001151231-1002-02-1002151231-1003-02-1001etc....What I'd like to do is include an ORDER BY statement that splits thestring, so that the order would be by the second set of four numbers(i.e. between the first and second - marks), followed by the third setof two numbers, and then by the last set of four numbers.How would I do something like this?--Sugapablo - Join Bytes!http://www.sugapablo.com | ICQ: 902845
I am developing database support for my application and I am using EDB. I would like to use sort orders to make the code easier but I was wondering if sort orders generate index tables. I mean, do they only sort the records during addition or they also generate index tables to speed up queries. In other words, do they make the database file bigger? In the MSDN documentation I can not find anything on this.
I have a requirement to calculate the % change in the number of orders received today with the number of orders that were received 3 days back. All data is in the same table. There is a received date column.
I have two count(*) queries - one for today and one for 3 days back running separately and getting the results. Is it possible I can get the % change in orders received from 3 days back and today in one query.Also if I want to get the number of orders received today between 12:00am today and current time. How would I modify the query.
I have an Orders table which has the following fields:
OrderID (PK, int, auto increment, not null) CustomerID (FK, int, null) PaymentDate (datetime, null) UserID (uniqueidentifier)
(and other irrelevant fields)
Basically, for a specific PaymentDate range (29th July 2014 - 26th August 2014, inclusive) I want to select all orders where they only appear once in the orders table based on the CustomerID, so I only want to know about them if they have a paid order (decided by PaymentDate not being null) in that date range, but also taking into account if they have ever had a paid order outside of that date range. I'll also be joining on to the aspnet_Users table to get the username assigned to that order.
I am trying to create a script file that will get me the total number of orders in july. How exactly would i say july because i know my syntax is wrong and I would be using sum instead of count right?
What i tried
use Cis11101_Northwind Declare @Julycount int Set @Julycount= (Select sum(*) From orders Where OrderDate = 'july') print 'The total orders for july is ' + Cast(@JulyCount as varchar)
I have a table of orders. I was asked to count the orders that fall into specific dollar buckets. Normally I would use a CASE statement for this, but in this case, there are over 100 different buckets!
For example, I need to count the orders in $5 increments up to $400. The CASE statement would look like this:
Code: CASE WHEN sum(revenue) BETWEEN 0.01 AND 5.00 THEN [0.01 to 5.00] WHEN sum(revenue) BETWEEN 5.01 AND 10.00 THEN [5.01 to 10.00] ... WHEN sum(revenue) BETWEEN 395.01 AND 400.00 THEN [395.01 to 400.00]
Is there an easier way to do this, maybe with a loop?