dnoeth - thanks, that works too. I had tried that, but I didn't know the syntax required providing a name for the derived table, so it wasn't working. I had tried:
select partner, sum(totalData)
from
(your union-query here
)
group by partner
which doesn't work. I neeed a better SQL...
Zathras, as it so happens, I'm using SQL Server.
Let me check ...
IT WORKS!
Thank you! I don't think I would have gotten that one very quickly on my own.
I have a table holding information on data sent:
CREATE TABLE DataSent
(SENDERKEY int,
RECEIVERKEY int,
SIZE int,
PROCESSDATE datetime,
... other irrelevant fields ...)
I need to generate a report showing the total quantity of data sent or received by a particular account, within a date...
Um, swampBoogie, I'm not sure how that will work.
Even if I put the where clause in the right place (before the group by) and change it to "Jan > 0 and Feb > 0" (which is what I want), SQL Server still gives me the "Invalid column name" error.
Anyway, I'm pretty certain I need something that...
I have a dynamically built query that returns monthly sales totals grouped by product sold, location and salesman. If the customer asked for results from 1/1/2006 to 2/15/2006, the query would look something like this:
select n.location,d.salesman_num, d.item_description,
(select...
Update: I tried just bypassing the view entirely and running the query against the underlying tables.
select n.N102_NAME as name,
n.N301_ADDRESSONE +' '+n.N302_ADDRESSTWO +' '+n.N401_CITY +', '+n.N402_STATE +' '+ n.N403_ZIP as address
,d.REF02_SL_SALESMANNUM as salesman_num...
OK, I cleared out the extra start/end dates.
select name, address, salesman_num,description,
(select ISNULL(SUM(v1.qty),0) from ViewForCustom867Download v1
where v1.customerkey = v0.customerkey and v1.name = v0.name
and v1.address = v0.address and v1.salesman_num = v0.salesman_num
and...
I have the apparently redundant start/end dates because the query is dynamically built based on a user supplied start/end date, but I'm also grouping the results by month. In the example above, I supplied a start date of 1-1-2005 and end date of 2-11-2005. I suppose that I could put some extra...
I have a view:
CREATE VIEW ViewForCustom867Download
AS
SELECT
h.customerkey,
d.REF02_SL_SALESMANNUM as salesman_num, d.PID05_F_ITEMDESC as description,
convert(int,d.QTY02_39_SHIPPEDQTY) as qty,d.LIN_UA_UPCCASECODE as upc,
convert(datetime,h.DTM02_035_DeliveryDate) as DeliveryDate...
Hmmm, that's getting closer. Now, however, when the script reaches the EXEC (@SQL_Command) line, it gives me the following message:
Server: Msg 137, Level 15, State 1, Line 1
Must declare the variable '@fooCount'.
@fooCount is previously declared in my script, and I can access it before and...
Steve - thanks, but in the actual application, I have to select a particular list of databases based on customer ID and a particular table for each DB. A stored procedure which goes through every database on the server doesn't help me.
Jay - the code you present builds the appropriate string...
I'm trying to clean up some highly inefficient ColdFusion code which loops through a long list of databases, running dynamically built SQL queries on each one. I'm considering moving the entire process into a stored procedure and would like to do something like the following:
/* simplified...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.