Showing posts with label rows. Show all posts
Showing posts with label rows. Show all posts

Sunday, March 25, 2012

Dimension theory design question.

If I have a sales fact table with 1000 sales to 20 different customers would I have 20 rows in my customer dimension table or 1000 rows? Each sales row has a customer, but many would be duplicates. Do I add a row to the customer dimension for each sale or each customer?

Thanks.

Hello! You will have 20 customer records in your customer dimension table and 1000 records in your sales fact table.

You will have a one to many relation between the customer dimension table and the fact table.

Select Distinct (TSQL) will help you with duplicates in the customer dimension.

HTH

Thomas Ivarsson

|||

Thanks.

To recap: I have an identity integer field for the surrogate key in the dimCustomer table and a business key field. I have two choices for the business key: I can use the CustomerID or the SalesNum from the OLTP. I gather from your response that I should use the CustomerID as the business key. Then when I load the dimension table, if a new sale goes to an existing customer, a new row will NOT be added to the dimCustomer table. When I subsequently load my fact table, I'll use the CustomerID in my sales row to point to the business key in the dimension table and retrieve the surrogate key which will be loaded into the fact table as the foreign key to dimCustomer and part of my aggregate key in the factSales table.

Did I say that right? (There's a whole lot of keys goin on.)

|||

Correct! You will only add customers when the customer business key is not in that dimension table.

Yes, it is good design to use integers, non business keys, as a primary key(dimension table) and foreign key(fact table)

You load the dimension table first and the fact table after and you update the keys in the way you have described.

The fact table will only have the surrogate keys and the dimension table both the business key and the surrogate key.

Regards

Thomas Ivarsson

Thursday, March 22, 2012

Digits converted to null

Hi,
Im loading data from excel source into a table with all the columns as varchar, I found out that rows from excel with digit value are transformed to Null values into the destination table.

One workaround was to add single quote at the beginning of the digits from the excel file. Is there a way in the SSIS to do the transformation instead ofmanually updating the excel file?

any help...tnx..

Not that I know of and I've spent some time looking. Reading data from Excel is tricky. For example, the data type of the column can change from row-to-row, and Excel can store data that doesn't match the defined data type. These are pretty big challenges for an OLE DB provider trying to read it like a table.
In several cases I've resorted to exporting my Excel source to a tab-delimited file for SSIS to read. At least you can automate this instead of having to manually fix each Excel file.|||You need to specify Import Mode by adding IMEX=1 to the connection string, in the Extended Properties argument along with the Excel version and HDR name/value pairs.

Please note that we have done our best to document this and other known issues in the topics for the Excel Source and the Excel Destination in BOL. This content has been further augmented for the upcoming Web refresh of BOL.

-Doug|||This type of problem was also applicable to DTS so this article should

probably still apply

Excel Inserts Null Values

(http://www.sqldts.com/default.aspx?254)

Allan

"DouglasL@.discussions.microsoft.com"

wrote in message

news:3b274106-b020-42bb-95cf-a1aeb554ea98@.discussions.microsoft.com:

> You need to specify Import Mode by adding IMEX=1 to the connection

> string, in the Extended Properties argument along with the Excel version

> and HDR name/value pairs.

>

> Please note that we have done our best to document this and other known

> issues in the topics for the Excel Source and the Excel Destination in

> BOL. This content has been further augmented for the upcoming Web

> refresh of BOL.

>

> -Doug

Wednesday, March 21, 2012

Difficult Query, with dynamically updated data between rows....

Hi Everybody,
I'm looking for some help putting together a stored procedure to do a
report for my shipping department. What they are looking for is a
report listing a SalesOrder (SO), some of its pertinent information,
and then a list of the inventory we have for that part. Here's the
catch. If the same part is to ship on two seperate SO's, the inventory
must change between them. For example:
SONum Part QTYReq QtyAvail LotNum
1 A 100 120 100k5
2 B 500 800 120j4
3 B 200 300 120j4
4 C 55 50 121b4
You'll notice that for part 'B', we had 800 in stock for the first so,
took off 500, leaving us with 300 to report for the second.
The problem is that I don't really know how to handle this. I don't
even know what to title this post!
So far, I have created temp tables to capture a snapshot of my
inventory (so that I can modify it without hurting the real data) and
to hold the list of SO's data.
My basic plan is to create a cursor on the SO Data, updating the
available inventory for that SO item, then updating the inventory
snapshot, so that on subsequent checks, the new, lower values are ready
to be used.
Is there a better way to do this? Will my plan be likely to succeed?
Thanks for any input you can offer! It is honestly appreciated.
Brian.you could use something like this (untested):
select
SONum, Part, QTYReq,
(QtyAvail - (select sum(t1.QTYReq) from your_table t1
where t1.part=t.part and t1.sonum<t.sonum)) QtyAvail ,
LotNum
from your_table t|||Hrm, I see how that goes...
Lets throw another wrench into the mix.
Add multiple lot numbers for a part so the output looks now something
like:
SONum Part QTYReq QtyAvail LotN
1 A 100 120 100k
2 B 500 360 120j
2 B 500 280 121j
2 B 500 198 122j
3 B 200 0 120j
3 B 200 140 121j
3 B 200 198 122j
4 C 55 50 21b4
How would you work that out? I'll keep trying on my own to see if I
can get it, but if you can suggest, I'd be most grateful.
Thanks,
Brian.|||using row_number(), it's a snap.
without OLAP functions, still doable, something like this:
drop table #lots
go
drop table #requests
go
create table #lots(LotN char(4), part char(1), qty smallint)
insert into #lots values('120j', 'B', 360)
insert into #lots values('121j', 'B', 280)
insert into #lots values('122j', 'B', 122)
create table #requests(SOnum smallint, part char(1), qty smallint)
insert into #requests values(2, 'B', 500)
insert into #requests values(3, 'B', 200)
go
select sonum, part, QTYReq,
case
when prev_reqs<prev_lots then QtyAvail
when prev_reqs between prev_lots and (prev_lots + QtyAvail) then
QtyAvail - prev_reqs + prev_lots
else 0 end QtyAvail,
lotN
from(
select r.sonum, r.part, r.qty QTYReq, l.qty QtyAvail, l.lotN,
isnull((select sum(qty) from #lots l1 where l1.part = l.part and
l1.lotN < l.lotN), 0) prev_lots,
isnull((select sum(qty) from #requests r1 where r1.part = r.part and
r1.SOnum < r.SOnum), 0) prev_reqs
from #lots l, #requests r where r.part = l.part
) t
order by sonum, lotN
note that you need more test data|||Okay! That looks promising...
I'll give that a try tomorrow morning.
Thanks for the response. It was more detailed than I had hoped for,
considering my lack of proper ddl and such.
Thanks again,
Brian|||Alexander (or anybody else),
I've taken your suggestion, and applied it to my situation. It very
nearly does the trick, but something about it just isn't right...I'll
pase the code following, but I'll talk about it up here...
With this particular dataset (ddl included this time :) ), what I have
is 3 seperate sales orders for a part, and 2 lots in inventory. Each
SO is for 400 parts, and the lots are 500 each.
For the first SO in the list it displays correctly. We have 2 lots of
500 to take the 400 out of...
But for the second SO, we should see that we have one lot of 100, and
another of 500, instead of both listing at 100.
The third SO, of course, should list one lot as empty, and the other as
having 200, instead of both listing at 0.
At this point, are we out of options as far as set operations go? I'm
still pondering the Cursor in the back of my mind, but I'd rather avoid
that if its possible.
Thanks again for aiding me. It is appreciated.
==== CODE BLOCK ====
drop table #lots
go
drop table #requests
go
create table #lots
(
customerID varchar(55)
, LotNumber char(44)
, PartNumber char(11)
, Quantity float
, lotPKey int
, departmentCode varchar(22)
, qtyReleased float
, qtyHold float
)
create table #requests
(
customerID varchar(55)
, shipDate datetime
, sortDate datetime
, SONumber varchar(22)
, SOLine varchar(22)
, customerPO varchar(22)
, partNumber varchar(11)
, partXRef varchar(22)
, descText varchar(99)
, qtyOpen float
, sortKey int IDENTITY(1,1)
)
-- -- generate the request data...
-- INSERT INTO #requests (
-- customerID
-- , shipDate
-- , SONumber
-- , SOLine
-- , customerPO
-- , partNumber
-- , partXRef
-- , descText
-- , qtyOpen
-- )
-- SELECT
-- UPPER(SOH.CustomerID)
-- , SOD.ScheduledShipDate
-- , SOH.SONumber
-- , SOD.SOLine
-- , SOH.CustomerPO
-- , SOD.PartNumber
-- , SOD.PartXReference
-- , PM.DescText
-- , SOD.QuantityOrdered - (SOD.QuantityShipped + SOD.QuantityReturned)
as QtyOpen
-- FROM SOHeader SOH
-- INNER JOIN SODetail SOD ON SOH.SONumber = SOD.SONumber
-- INNER JOIN PartMaster PM ON SOD.PartNumber = PM.PartNumber
-- WHERE SOD.ScheduledShipDate >= '1/1/2000' AND SOD.ScheduledShipDate
<= '11/13/2005'
-- AND SOD.PartNumber LIKE '600879%' --600879
-- AND SOH.ClosedFlag <> 1
-- AND SOD.ClosedFlag <> 1
-- ORDER BY
-- UPPER(SOH.CustomerID)
-- , SOD.PartNumber
-- , SOD.ScheduledShipDate
-- , SOH.SONumber
-- , SOD.SOLine
--
INSERT INTO #requests
(customerID , shipDate, SONumber , SOLine, customerPO , partNumber ,
partXRef , descText , qtyOpen)
VALUES ('ACME', '11/01/2005', 'SO0510001', '001', 'xyz', '600111',
'z987', 'ACME Foot Creme', 400)
INSERT INTO #requests
(customerID , shipDate, SONumber , SOLine, customerPO , partNumber ,
partXRef , descText , qtyOpen)
VALUES ('ACME', '11/11/2005', 'SO0510001', '001', 'xyz', '600111',
'z987', 'ACME Foot Creme', 400)
INSERT INTO #requests
(customerID , shipDate, SONumber , SOLine, customerPO , partNumber ,
partXRef , descText , qtyOpen)
VALUES ('ACME', '11/21/2005', 'SO0510001', '001', 'xyz', '600111',
'z987', 'ACME Foot Creme', 400)
-- --generate the lots data
-- INSERT INTO #lots
-- (
-- LotNumber
-- , PartNumber
-- , Quantity
-- , lotPKey
-- , departmentCode
-- , customerID
-- )
-- SELECT
-- IL.SNLotNumber
-- , IL.PartNumber
-- , IL.Quantity
-- , IL.InventoryLots_PKey
-- , IL.DepartmentCode
-- , P.SUOCode
-- FROM InventoryLots IL
-- INNER JOIN PartMaster P ON IL.PartNumber = P.PartNumber
-- WHERE IL.PartNumber LIKE '6%'
INSERT INTO #lots
(LotNumber, PartNumber, Quantity, lotPKey, departmentCode, CustomerID)
VALUES ('123j4' , '600111', 500, 1, 'FGINR', 'ACME')
INSERT INTO #lots
(LotNumber, PartNumber, Quantity, lotPKey, departmentCode, CustomerID)
VALUES ('124j4' , '600111', 500, 1, 'FGINR', 'ACME')
UPDATE #lots
SET qtyReleased = Quantity
FROM #lots
WHERE DepartmentCode = 'FGINR'
AND CustomerID <> 'CP'
UPDATE #lots
SET qtyReleased = Quantity
FROM #lots
WHERE DepartmentCode = 'FGINP'
AND CustomerID = 'CP'
UPDATE #lots
SET qtyHold = Quantity
FROM #lots
WHERE DepartmentCode = 'HOLD FGIN'
AND CustomerID <> 'CP'
UPDATE #lots
SET qtyHold = Quantity
FROM #lots
WHERE DepartmentCode = 'HOLDN FGIN'
AND CustomerID = 'CP'
--set the sort date for all shipments...
UPDATE #requests
SET sortDate = Z.minshipdate
FROM #requests R
INNER JOIN
(
SELECT PartNumber, MIN(shipDate) as minshipdate FROM #requests
GROUP BY PartNumber
) Z ON R.PartNumber = Z.PartNumber
select
customerID
, shipDate
, sortDate
, SONumber
, SOLine
, customerPO
, partNumber
, partXRef
, descText
, qtyOpen
--, qtyReleased
, case
when prev_reqs < prev_lots then qtyReleased
when prev_reqs between prev_lots and (prev_lots + qtyReleased) then
qtyReleased - prev_reqs + prev_lots
else 0
end qtyReleased
, qtyHold
, lotNumber
from(
select
r.customerID
, r.shipDate
, r.sortDate
, r.SONumber
, r.SOLine
, r.customerPO
, r.partNumber
, r.partXRef
, r.descText
, ISNULL(r.qtyOpen , 0) qtyOpen
, ISNULL(l.qtyReleased , 0) qtyReleased
, ISNULL(l.qtyHold , 0) qtyHold
, l.lotNumber
, isnull(
(select sum(qtyReleased)
from #lots l1
where
l1.partNumber = l.partNumber and
l1.lotPKey < l.lotPKey
), 0) prev_lots
, isnull(
(select sum(qtyOpen)
from #requests r1
where r1.partNumber = r.partNumber
and r1.sortKey < r.sortKey
), 0) prev_reqs
from #lots l, #requests r
where r.partNumber = l.partNumber
) t
--order by sonum, lotN|||On 10 Nov 2005 08:08:50 -0800, Brian Ackermann wrote:

>Alexander (or anybody else),
>I've taken your suggestion, and applied it to my situation. It very
>nearly does the trick, but something about it just isn't right...I'll
>pase the code following, but I'll talk about it up here...
>With this particular dataset (ddl included this time :) ), what I have
>is 3 seperate sales orders for a part, and 2 lots in inventory. Each
>SO is for 400 parts, and the lots are 500 each.
>For the first SO in the list it displays correctly. We have 2 lots of
>500 to take the 400 out of...
>But for the second SO, we should see that we have one lot of 100, and
>another of 500, instead of both listing at 100.
>The third SO, of course, should list one lot as empty, and the other as
>having 200, instead of both listing at 0.
>At this point, are we out of options as far as set operations go? I'm
>still pondering the Cursor in the back of my mind, but I'd rather avoid
>that if its possible.
>Thanks again for aiding me. It is appreciated.
Hi Brian,
Thabks for posting DDL and sample data. However, I'm not sure if your
data is correct. You mention three sales orders and two lots in your
post, yet I see only one SONumber and one LotNumber in the output!
Anyway - this kind of problem CAN be tackled with a setbased operation,
but they often perform very bad. Because they require some correlated
subqueries and/or self-joins, the typical query plan often involves
multiple table scans. If you can find a cursor-based solution that only
needs to iterate over all rows once, it'll probably be faster than a
set-based version.
If you still want to try a set-based solution, I'll try to help you. But
not now - it's past midnight here; I'd just make errors. Please try to
explain me how your data holds three sales orders and two lot numbers,
even though I see only one of each. Or correct your data if you made a
mistake. I'll take a jab at a set-based solution later (after seeing an
explanation or a correction of your test data).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||You might want to look at a pair of articles I have posted on
DBAzine.com on inventory control queries.sql

Difficult Combining Rows queston...followup

Greetings,
I'm working to combine rows based on a time window and I am hoping to
be able to write a stored procedure to do this for me, rather than have
parse through all this data in my program. I'm not very well versed
with T-SQL syntax.. just enough to get by selecting using inner joins,
updating and inserting... thats about it. (Hence why I am here.)
The raw data I have below looks like this:
groupID, StartTime, EndTime, Min, Max, Points
1, 2005-10-05 06:00, 2005-10-05 06:14:59, 7, 32, 13
1, 2005-10-05 06:15, 2005-10-05 06:29:59, 5, 29, 6
1, 2005-10-05 06:30, 2005-10-05 06:44:59, 5, 28, 4
1, 2005-10-05 06:45, 2005-10-05 06:59:59, 5, 29, 16
1, 2005-10-05 07:00, 2005-10-05 07:14:59, 5, 23, 13
1, 2005-10-05 07:15, 2005-10-05 07:29:59, 5, 25, 18
1, 2005-10-05 07:30, 2005-10-05 07:44:59, 5, 34, 49
1, 2005-10-05 07:45, 2005-10-05 07:59:59, 5, 31, 49
Pretty straight forward; you can see each entry is a 15 minute time
interval. What I want to be able to do is to use a view or a stored
procedure to view this in grouped chunks, like below
30 minute chunks
groupID, StartTime, EndTime, Min, Max, Points
1, 2005-10-05 06:00, 2005-10-05 06:29:59, 5, 32, 19
1, 2005-10-05 06:30, 2005-10-05 06:59:59, 5, 29, 20
1, 2005-10-05 07:00, 2005-10-05 07:29:59, 5, 25, 36
1, 2005-10-05 07:30, 2005-10-05 07:59:59, 5, 34, 98
1 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
1, 2005-10-05 06:00, 2005-10-05 06:59:59, 5, 32, 39
1, 2005-10-05 07:00, 2005-10-05 07:59:59, 5, 34, 129
2 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
Since originally posting my question, I have learned from John Bell
that I can use this to solve the 1 hour problem at hand.
SELECT GROUPID,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime) AS StartTime,
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Starttime),Starttime)))
AS EndTime,
Min([Min]), Max([Max]), SUM([Points])
FROM Readings
GROUP BY GroupId,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime),
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Starttime),Starttime)))
This makes sense for the hour instance... The hour instance also seems
to be the easiest one to solve. This query simply selects and groups
the start times to starttime-it's own minutes, end time to
starttime-it's own minutes + 1 hour. That works our very well for the
one hour case.
When I move to a two hour time window, we run into problems. Using that
exact query replacing "hour,1" for "hour, 2" will produce results that
look like this
groupID, StartTime, EndTime, Min, Max, Points
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
1, 2005-10-05 07:00, 2005-10-05 08:59:59, 7, 32, 150
1, 2005-10-05 08:00, 2005-10-05 09:59:59, 6, 36, 172
This is where it gets confusing. The problem with that is that the
group by is still grouping in one hour chunks, because the 'adjusted'
start time for the second hour is not the same as the 'adjusted' start
time for the first hour. The start and end time might look ok, but the
rest of the data does not. Also, since this is a GROUP BY clause, a
working query should not produce overlapping results(in this case,
seemingly overlapping).
So for this 2 hour case (and upwards) I am looking for a solution to
get that start time query to go back
It's almost like i need to do something like IF statments in my
SELECT... not sure if that is possible or not.
Similar problems occur when you go to do half hour groupings. All four
15 minute chunks get floored and grouped together, even though you can
easily get the end time to report x:29:29.
What a mess, it seems like I am trying to do the impossible.
Any suggestions? Please ask me to clarify if necessary.
Jason
Got it. Well part of it. Here is the multiple hour verison. Yay for
integer division.
--SELECT in TWO HOUR INCREMENTS
SELECT groupID,
DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTim e)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))
AS Startime,
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTim e)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))))
AS Endtime,
MIN([Min]) as MinSpeed,
MAX([Max]) as MaxSpeed,
SUM([Points]) as Total
FROM TABLE_NAME
WHERE groupID='1'
GROUP BY groupID,
DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTim e)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime)),
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTim e)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))))
This will work for 1,2,3,4, if you replace all instances of 2 with
1,2,3,4, etc. which can be done in code very easily.
Now to figure out the 30 minute version.
This query is so repetetive, I wish I could use variable names instead
of rewriting the whole thing... the EndTime calculation uses the whole
start time calculation. and the GROUP BY clauses are copies of what is
above. Using AS does not seem to work in these cases. Oh well.
Jason
|||On 10 Nov 2005 12:35:53 -0800, jasonsgeiger@.gmail.com wrote:

>Greetings,
>I'm working to combine rows based on a time window and I am hoping to
>be able to write a stored procedure to do this for me, rather than have
>parse through all this data in my program. I'm not very well versed
>with T-SQL syntax.. just enough to get by selecting using inner joins,
>updating and inserting... thats about it. (Hence why I am here.)
(snip)
Hi Jason,
I just posted a reply to your message in the original thread (in
microsoft.public.sqlserver.programming).
Please don't post multiple copies of the same question. I'd hate to see
someone else spend time to figure this out, becuase he or she is not
aware that I have already answered the question.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Difficult Combining Rows queston...followup

Greetings,
I'm working to combine rows based on a time window and I am hoping to
be able to write a stored procedure to do this for me, rather than have
parse through all this data in my program. I'm not very well versed
with T-SQL syntax.. just enough to get by selecting using inner joins,
updating and inserting... thats about it. (Hence why I am here.)
The raw data I have below looks like this:
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:14:59, 7, 32, 13
1, 2005-10-05 06:15, 2005-10-05 06:29:59, 5, 29, 6
1, 2005-10-05 06:30, 2005-10-05 06:44:59, 5, 28, 4
1, 2005-10-05 06:45, 2005-10-05 06:59:59, 5, 29, 16
1, 2005-10-05 07:00, 2005-10-05 07:14:59, 5, 23, 13
1, 2005-10-05 07:15, 2005-10-05 07:29:59, 5, 25, 18
1, 2005-10-05 07:30, 2005-10-05 07:44:59, 5, 34, 49
1, 2005-10-05 07:45, 2005-10-05 07:59:59, 5, 31, 49
Pretty straight forward; you can see each entry is a 15 minute time
interval. What I want to be able to do is to use a view or a stored
procedure to view this in grouped chunks, like below
30 minute chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:29:59, 5, 32, 19
1, 2005-10-05 06:30, 2005-10-05 06:59:59, 5, 29, 20
1, 2005-10-05 07:00, 2005-10-05 07:29:59, 5, 25, 36
1, 2005-10-05 07:30, 2005-10-05 07:59:59, 5, 34, 98
1 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:59:59, 5, 32, 39
1, 2005-10-05 07:00, 2005-10-05 07:59:59, 5, 34, 129
2 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
Since originally posting my question, I have learned from John Bell
that I can use this to solve the 1 hour problem at hand.
SELECT GROUPID,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime) AS StartTime,
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Startt
ime),Starttime)))
AS EndTime,
Min([Min]), Max([Max]), SUM([Points])
FROM Readings
GROUP BY GroupId,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime),
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Startt
ime),Starttime)))
This makes sense for the hour instance... The hour instance also seems
to be the easiest one to solve. This query simply selects and groups
the start times to starttime-it's own minutes, end time to
starttime-it's own minutes + 1 hour. That works our very well for the
one hour case.
When I move to a two hour time window, we run into problems. Using that
exact query replacing "hour,1" for "hour, 2" will produce results that
look like this
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
1, 2005-10-05 07:00, 2005-10-05 08:59:59, 7, 32, 150
1, 2005-10-05 08:00, 2005-10-05 09:59:59, 6, 36, 172
This is where it gets confusing. The problem with that is that the
group by is still grouping in one hour chunks, because the 'adjusted'
start time for the second hour is not the same as the 'adjusted' start
time for the first hour. The start and end time might look ok, but the
rest of the data does not. Also, since this is a GROUP BY clause, a
working query should not produce overlapping results(in this case,
seemingly overlapping).
So for this 2 hour case (and upwards) I am looking for a solution to
get that start time query to go back
It's almost like i need to do something like IF statments in my
SELECT... not sure if that is possible or not.
Similar problems occur when you go to do half hour groupings. All four
15 minute chunks get floored and grouped together, even though you can
easily get the end time to report x:29:29.
What a mess, it seems like I am trying to do the impossible.
Any suggestions? Please ask me to clarify if necessary.
JasonGot it. Well part of it. Here is the multiple hour verison. Yay for
integer division.
--SELECT in TWO HOUR INCREMENTS
SELECT groupID,
DATEADD(hour,- (DATEPART(hour,StartTime))+(DATEPART(hou
r,StartTime)/2)*2,DATE
ADD(minute,-DATEPART(minute,StartTime),StartTime))
AS Startime,
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime
))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime)
,StartTime))))
AS Endtime,
MIN([Min]) as MinSpeed,
MAX([Max]) as MaxSpeed,
SUM([Points]) as Total
FROM TABLE_NAME
WHERE groupID='1'
GROUP BY groupID,
DATEADD(hour,- (DATEPART(hour,StartTime))+(DATEPART(hou
r,StartTime)/2)*2,DATE
ADD(minute,-DATEPART(minute,StartTime),StartTime)),
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime
))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime)
,StartTime))))
This will work for 1,2,3,4, if you replace all instances of 2 with
1,2,3,4, etc. which can be done in code very easily.
Now to figure out the 30 minute version.
This query is so repetetive, I wish I could use variable names instead
of rewriting the whole thing... the EndTime calculation uses the whole
start time calculation. and the GROUP BY clauses are copies of what is
above. Using AS does not seem to work in these cases. Oh well.
Jason|||On 10 Nov 2005 12:35:53 -0800, jasonsgeiger@.gmail.com wrote:

>Greetings,
>I'm working to combine rows based on a time window and I am hoping to
>be able to write a stored procedure to do this for me, rather than have
>parse through all this data in my program. I'm not very well versed
>with T-SQL syntax.. just enough to get by selecting using inner joins,
>updating and inserting... thats about it. (Hence why I am here.)
(snip)
Hi Jason,
I just posted a reply to your message in the original thread (in
microsoft.public.sqlserver.programming).
Please don't post multiple copies of the same question. I'd hate to see
someone else spend time to figure this out, becuase he or she is not
aware that I have already answered the question.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Difficult Combining Rows queston...followup

Greetings,
I'm working to combine rows based on a time window and I am hoping to
be able to write a stored procedure to do this for me, rather than have
parse through all this data in my program. I'm not very well versed
with T-SQL syntax.. just enough to get by selecting using inner joins,
updating and inserting... thats about it. (Hence why I am here.)
The raw data I have below looks like this:
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:14:59, 7, 32, 13
1, 2005-10-05 06:15, 2005-10-05 06:29:59, 5, 29, 6
1, 2005-10-05 06:30, 2005-10-05 06:44:59, 5, 28, 4
1, 2005-10-05 06:45, 2005-10-05 06:59:59, 5, 29, 16
1, 2005-10-05 07:00, 2005-10-05 07:14:59, 5, 23, 13
1, 2005-10-05 07:15, 2005-10-05 07:29:59, 5, 25, 18
1, 2005-10-05 07:30, 2005-10-05 07:44:59, 5, 34, 49
1, 2005-10-05 07:45, 2005-10-05 07:59:59, 5, 31, 49
Pretty straight forward; you can see each entry is a 15 minute time
interval. What I want to be able to do is to use a view or a stored
procedure to view this in grouped chunks, like below
30 minute chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:29:59, 5, 32, 19
1, 2005-10-05 06:30, 2005-10-05 06:59:59, 5, 29, 20
1, 2005-10-05 07:00, 2005-10-05 07:29:59, 5, 25, 36
1, 2005-10-05 07:30, 2005-10-05 07:59:59, 5, 34, 98
1 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 06:59:59, 5, 32, 39
1, 2005-10-05 07:00, 2005-10-05 07:59:59, 5, 34, 129
2 hour chunks
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
Since originally posting my question, I have learned from John Bell
that I can use this to solve the 1 hour problem at hand.
SELECT GROUPID,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime) AS StartTime,
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Starttime),Starttime)))
AS EndTime,
Min([Min]), Max([Max]), SUM([Points])
FROM Readings
GROUP BY GroupId,
DATEADD(minute,-DATEPART(minute,Starttime),Starttime),
DATEADD(millisecond,-3,DATEADD(hour,1,DATEADD(minute,-DATEPART(minute,Starttime),Starttime)))
This makes sense for the hour instance... The hour instance also seems
to be the easiest one to solve. This query simply selects and groups
the start times to starttime-it's own minutes, end time to
starttime-it's own minutes + 1 hour. That works our very well for the
one hour case.
When I move to a two hour time window, we run into problems. Using that
exact query replacing "hour,1" for "hour, 2" will produce results that
look like this
groupID, StartTime, EndTime, Min, Max, Points
----
1, 2005-10-05 06:00, 2005-10-05 07:59:59, 5, 34, 168
1, 2005-10-05 07:00, 2005-10-05 08:59:59, 7, 32, 150
1, 2005-10-05 08:00, 2005-10-05 09:59:59, 6, 36, 172
This is where it gets confusing. The problem with that is that the
group by is still grouping in one hour chunks, because the 'adjusted'
start time for the second hour is not the same as the 'adjusted' start
time for the first hour. The start and end time might look ok, but the
rest of the data does not. Also, since this is a GROUP BY clause, a
working query should not produce overlapping results(in this case,
seemingly overlapping).
So for this 2 hour case (and upwards) I am looking for a solution to
get that start time query to go back
It's almost like i need to do something like IF statments in my
SELECT... not sure if that is possible or not.
Similar problems occur when you go to do half hour groupings. All four
15 minute chunks get floored and grouped together, even though you can
easily get the end time to report x:29:29.
What a mess, it seems like I am trying to do the impossible.
Any suggestions? Please ask me to clarify if necessary.
JasonGot it. Well part of it. Here is the multiple hour verison. Yay for
integer division.
--SELECT in TWO HOUR INCREMENTS
SELECT groupID,
DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))
AS Startime,
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))))
AS Endtime,
MIN([Min]) as MinSpeed,
MAX([Max]) as MaxSpeed,
SUM([Points]) as Total
FROM TABLE_NAME
WHERE groupID='1'
GROUP BY groupID,
DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime)),
DATEADD(millisecond,-3,DATEADD(hour,2,DATEADD(hour,-(DATEPART(hour,StartTime))+(DATEPART(hour,StartTime)/2)*2,DATEADD(minute,-DATEPART(minute,StartTime),StartTime))))
This will work for 1,2,3,4, if you replace all instances of 2 with
1,2,3,4, etc. which can be done in code very easily.
Now to figure out the 30 minute version.
This query is so repetetive, I wish I could use variable names instead
of rewriting the whole thing... the EndTime calculation uses the whole
start time calculation. and the GROUP BY clauses are copies of what is
above. Using AS does not seem to work in these cases. Oh well.
Jason|||On 10 Nov 2005 12:35:53 -0800, jasonsgeiger@.gmail.com wrote:
>Greetings,
>I'm working to combine rows based on a time window and I am hoping to
>be able to write a stored procedure to do this for me, rather than have
>parse through all this data in my program. I'm not very well versed
>with T-SQL syntax.. just enough to get by selecting using inner joins,
>updating and inserting... thats about it. (Hence why I am here.)
(snip)
Hi Jason,
I just posted a reply to your message in the original thread (in
microsoft.public.sqlserver.programming).
Please don't post multiple copies of the same question. I'd hate to see
someone else spend time to figure this out, becuase he or she is not
aware that I have already answered the question.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)sql

Monday, March 19, 2012

Differential rows

I am using SSIS to replicate data from an AS400 mainframe to a SQL destination. I am using a lookup column to see if the primary key is duplicated and if not, it will INSERT the row. This is all working fine. What I need to know is can I also use the Lookup transformation to look for differential data and then UPDATE the row? The primary key of the table will never change, however the data might and I need the package to recognize that this is a modified row on the mainframe and that the same row on the SQL destination server needs to be updated.

Thanks for any useful information.

I believe that I found a solution to my own problem. It looks like I need to use the Slowly Changing Dimension transformation. So far in running the test data, this is exactly what I need.

Differential rows

I am using SSIS to replicate data from an AS400 mainframe to a SQL destination. I am using a lookup column to see if the primary key is duplicated and if not, it will INSERT the row. This is all working fine. What I need to know is can I also use the Lookup transformation to look for differential data and then UPDATE the row? The primary key of the table will never change, however the data might and I need the package to recognize that this is a modified row on the mainframe and that the same row on the SQL destination server needs to be updated.

Thanks for any useful information.

I believe that I found a solution to my own problem. It looks like I need to use the Slowly Changing Dimension transformation. So far in running the test data, this is exactly what I need.|||

Thank you so much for the answer to your own question! I've been using lookup and conditional split transformation to check if non-key columns have been modified. Writing an expression to compare all columns in a 40-column table has been making me go crazy. SCD does it all for you! In the literature I had in hand SCD is always used in the data warehouse context. Since I'm using IS for the data migration (only), I've never considered it as a transforamtion that could be of any use to me.

Sunday, March 11, 2012

Differential Backup...

Why are my differential backups of the same size as full database backups ?
I am just adding few rows to it daily.
Thanks.:rolleyes:I'm having the same problem - any ideas on why my differential size is almost as big as a full?|||I found out that there was optmization job that was running on that database every night, just before the differential backup.

Then I changed the job to run once a week before I take a full database backup, and since then I did not had this problem.

Thanks.

Differential Backup not smaller than the full backup

Hi,

Using SQL Server 2005, we have a 2.8Gb database under the Simple recovery model. The database contains ~50M rows and each night ~60k rows are loaded(appended) to the database by a SSIS task.

We configured a Maintenance Plan which is executed once a week to perform a full backup of the database. The resulting backup file is ~2.8Gb, as expected.

We also configured another Maintenance Plan which is executed every day, a few hours after the SSIS task is executed, to perform a differential backup. To our surprise, the resulting backup file is about the same size as the full backup, ~2.8Gb when it should only be a few MB (only 60k rows are added to the database)

When we launch the "Restore Database" wizzard we clearly see the different backup set, Full and Differential but they all have about the same size (same for the physical backup file on disk).

Is there anything we are missing, why are the differential backup that big?

Thanks for any advice.

Hi Math,

When u r setting Differential backup have u checked for options like
Append to the existing backup set
Overwrite all existing backup sets

when we use append to the existing backup set it appends to the existing differential backup set, so the differential backup obviously increases & even nearer to the full backup size.

Regards
Karna|||

Can you post the exact syntax that you're using?

That would help to narrow it down.

Thanks,

|||Hi,

After getting into SQL Server 2005 Management Studio, in the Backup task of certain database when u click on options u'll find option buttons such as
Append to the existing backup set
Overwrite all existing backup sets

From these above options u can choose any one of them, by default Append to the existing backup set is enabled.

I hope this would helpful.

Regards
Karna

Differential Backup not smaller than the full backup

Hi,

Using SQL Server 2005, we have a 2.8Gb database under the Simple recovery model. The database contains ~50M rows and each night ~60k rows are loaded(appended) to the database by a SSIS task.

We configured a Maintenance Plan which is executed once a week to perform a full backup of the database. The resulting backup file is ~2.8Gb, as expected.

We also configured another Maintenance Plan which is executed every day, a few hours after the SSIS task is executed, to perform a differential backup. To our surprise, the resulting backup file is about the same size as the full backup, ~2.8Gb when it should only be a few MB (only 60k rows are added to the database)

When we launch the "Restore Database" wizzard we clearly see the different backup set, Full and Differential but they all have about the same size (same for the physical backup file on disk).

Is there anything we are missing, why are the differential backup that big?

Thanks for any advice.

Hi Math,

When u r setting Differential backup have u checked for options like
Append to the existing backup set
Overwrite all existing backup sets

when we use append to the existing backup set it appends to the existing differential backup set, so the differential backup obviously increases & even nearer to the full backup size.

Regards
Karna|||

Can you post the exact syntax that you're using?

That would help to narrow it down.

Thanks,

|||Hi,

After getting into SQL Server 2005 Management Studio, in the Backup task of certain database when u click on options u'll find option buttons such as
Append to the existing backup set
Overwrite all existing backup sets

From these above options u can choose any one of them, by default Append to the existing backup set is enabled.

I hope this would helpful.

Regards
Karna

Wednesday, March 7, 2012

Different Size Columns in Different Table Rows?

I'm trying to recreate something that I could do in Crystal Reports and have
hit a wall with Report Designer.
I want to create two (or more) header rows and two (or more) detail rows
with each column width different from the column width from the row above
(or below). I found how to add more header and detail rows but the column
widths remain the same for each row and cannot be adjusted separately. What
I'd like to to is to "merge" table columns for one report row into just one
column with the other row remaining as two columns.
For example, I want a report where the first row of detail contains multiple
columns that contains information about a database column, but then the next
detail row should only contain ONE column.
Type of Note Date of Note Author of Note
Note Text
---
Addendum 10/17/07 Shakespeare
This is the text of the note of an addendum written by Shakespeare
Is there a way to do this with RS, or is there some workaround?
Thanks for any help.Never mind (again) ;) I found the Merge Cells right-click command.
"Don Miller" <nospam@.nospam.com> wrote in message
news:%23HQrXMNEIHA.4752@.TK2MSFTNGP04.phx.gbl...
> I'm trying to recreate something that I could do in Crystal Reports and
> have hit a wall with Report Designer.
> I want to create two (or more) header rows and two (or more) detail rows
> with each column width different from the column width from the row above
> (or below). I found how to add more header and detail rows but the column
> widths remain the same for each row and cannot be adjusted separately.
> What I'd like to to is to "merge" table columns for one report row into
> just one column with the other row remaining as two columns.
> For example, I want a report where the first row of detail contains
> multiple columns that contains information about a database column, but
> then the next detail row should only contain ONE column.
> Type of Note Date of Note Author of Note
> Note Text
> ---
> Addendum 10/17/07 Shakespeare
> This is the text of the note of an addendum written by Shakespeare
> Is there a way to do this with RS, or is there some workaround?
> Thanks for any help.
>

Saturday, February 25, 2012

Different no. of rows returned in SEM vs QA

Hi,
Any idea why when I run a SELECT stament in Query anaylser it returns 45 rows. But when I create the exact same SQL as a view in Enterprise manager it only returns 44 rows?
Thanks,
AlphCould you kindly post the query, so that we can help you better.|||Its a union query with 12 Selects. Here is the first select:

SELECT
dbo.tblWBS.PSWBS AS [PSWBS Code],
ConcatenatedWBS AS [CWBS Code],
case when CR is null then 'R' else 'C' end AS [Capital / Revenue],
NDACost AS [Cost Element],
SUM(dbo.udfBCWScost (NDACost,FiscalYear,Apr_Cost,dbo.tblWBS.PSWBS )) as Amount,
'01-04-' + ltrim(rtrim(str(FiscalYear))) AS [Start Date],
'30-04-' + ltrim(rtrim(str(FiscalYear))) AS [Finish Date],
left(dbo.tblWBS.wbs,6) + Right(dbo.tblWBS.wbs,5) AS [Charge Code]

FROM dbo.tblBCWSMonthly INNER JOIN
dbo.tblBCWSYearly ON dbo.tblBCWSMonthly.RecordId = dbo.tblBCWSYearly.RecordUid INNER JOIN
dbo.tblWBS ON dbo.tblBCWSYearly.WBSUId = dbo.tblWBS.WBSuid

WHERE (dbo.tblWBS.EPSLvl4 = N'1.1.5.17') and dbo.tblWBS.PSWBS = '1.1.5.17.10.01.17001.00000.30 '

GROUP BY dbo.tblWBS.PSWBS, ConcatenatedWBS, CR, NDACost,'01-04-' + ltrim(rtrim(str(FiscalYear))),'30-04-' + ltrim(rtrim(str(FiscalYear))),dbo.tblWBS.wbs

HAVING SUM(dbo.udfBCWScost (NDACost,FiscalYear,Apr_Cost,dbo.tblWBS.PSWBS )) <> 0

UNION ALL

>> Then another 11 select statements|||Check the "Set concat_null_yields_null" setting in your Query Analyzer Connection Properties dialog box. Try toggling it, as it may be set different than your Server default.

Sunday, February 19, 2012

different datatypes with UPDATE or INSERT

I'm writing an SP that retrieves data on a linked SQL server, and
selectively updates or inserts like-named rows on the local server. Two
columns on the remote server are Mileage varchar(25) and Price varchar(25),
whereas on the local server the datatypes are INT and MONEY.
As an example of what's needed for 3 sample rows:
Mileage (remote) = 23,456; 'Call for Details'; 56,789
Mileage (local) = 23,456; NULL; 56,789
Price (remote) = $9,995.00; 'Call Us'; $14,900.00
Price (local) = $9,995.00; 'NULL'; $14,900.00
How does SQL Server handle an UPDATE or INSERT INTO in this situation? In
other words, if there are 'non-int' or 'non-money' values coming over from
the remote server, will SQL Server automatically convert these 'invalid'
values to NULL, or do I need to handle it somehow, maybe via a CASE
expression in the UPDATE or INSERT INTO, or...?
Thanks.
Message posted via http://www.webservertalk.comSQL Server will attempt a cast from a character field to a numeric. If it
fails, it will throw an error. A better option would be casting yourself and
logging any failures, including parameters that caused the failure. Humans
can then read the log and correct the data.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"The Gekkster via webservertalk.com" wrote:

> I'm writing an SP that retrieves data on a linked SQL server, and
> selectively updates or inserts like-named rows on the local server. Two
> columns on the remote server are Mileage varchar(25) and Price varchar(25)
,
> whereas on the local server the datatypes are INT and MONEY.
> As an example of what's needed for 3 sample rows:
> Mileage (remote) = 23,456; 'Call for Details'; 56,789
> Mileage (local) = 23,456; NULL; 56,789
> Price (remote) = $9,995.00; 'Call Us'; $14,900.00
> Price (local) = $9,995.00; 'NULL'; $14,900.00
> How does SQL Server handle an UPDATE or INSERT INTO in this situation? In
> other words, if there are 'non-int' or 'non-money' values coming over from
> the remote server, will SQL Server automatically convert these 'invalid'
> values to NULL, or do I need to handle it somehow, maybe via a CASE
> expression in the UPDATE or INSERT INTO, or...?
> Thanks.
> --
> Message posted via http://www.webservertalk.com
>|||It will try to automatically convert the data from varchar to integer.
However, if any value in the insert is invalid, it will crash. A good way
to handle this is using an Instead Of trigger. Instead of just inserting
the data, you run a check on the data to see if it is valid. Bad data goes
into an exception table, good into the real table.
There are quite a few different routines around to validate that a value is
a reasonable numeric value, but you will likely not want to use isNumeric as
it is very liberal. Search on groups.google.com for isNumeric and you will
see that is covered quite often.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"The Gekkster via webservertalk.com" <forum@.nospam.webservertalk.com> wrote in
message news:852fc5294d584b37b647b85f7d799e95@.SQ
webservertalk.com...
> I'm writing an SP that retrieves data on a linked SQL server, and
> selectively updates or inserts like-named rows on the local server. Two
> columns on the remote server are Mileage varchar(25) and Price
> varchar(25),
> whereas on the local server the datatypes are INT and MONEY.
> As an example of what's needed for 3 sample rows:
> Mileage (remote) = 23,456; 'Call for Details'; 56,789
> Mileage (local) = 23,456; NULL; 56,789
> Price (remote) = $9,995.00; 'Call Us'; $14,900.00
> Price (local) = $9,995.00; 'NULL'; $14,900.00
> How does SQL Server handle an UPDATE or INSERT INTO in this situation? In
> other words, if there are 'non-int' or 'non-money' values coming over from
> the remote server, will SQL Server automatically convert these 'invalid'
> values to NULL, or do I need to handle it somehow, maybe via a CASE
> expression in the UPDATE or INSERT INTO, or...?
> Thanks.
> --
> Message posted via http://www.webservertalk.com|||You need to test the values in the update, and update the local table to nul
l
when the remote value is not numeric... (This should handle 99.99% of teh
cases
Update <Table> Set
LocalCol = Case IsNumeric(RemoteCol)
When 1 Then Cast (RemoteCol as Integer)
Else Null End
From ...
"The Gekkster via webservertalk.com" wrote:

> I'm writing an SP that retrieves data on a linked SQL server, and
> selectively updates or inserts like-named rows on the local server. Two
> columns on the remote server are Mileage varchar(25) and Price varchar(25)
,
> whereas on the local server the datatypes are INT and MONEY.
> As an example of what's needed for 3 sample rows:
> Mileage (remote) = 23,456; 'Call for Details'; 56,789
> Mileage (local) = 23,456; NULL; 56,789
> Price (remote) = $9,995.00; 'Call Us'; $14,900.00
> Price (local) = $9,995.00; 'NULL'; $14,900.00
> How does SQL Server handle an UPDATE or INSERT INTO in this situation? In
> other words, if there are 'non-int' or 'non-money' values coming over from
> the remote server, will SQL Server automatically convert these 'invalid'
> values to NULL, or do I need to handle it somehow, maybe via a CASE
> expression in the UPDATE or INSERT INTO, or...?
> Thanks.
> --
> Message posted via http://www.webservertalk.com
>|||That's the same conclusion I came to. Even though IsNumeric may not be
'ideal' it seems to serve the purpose here well.
Thanks to all for the input.
Message posted via http://www.webservertalk.com

different color on odd rows

Hi all.
How do i get a different color on odd rows in a table or matrix?
/ChrsitianAt the end of this posting are two reports that demonstrate how to alternate
row colors on a table and a matrix.
--
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Christian Larsen" <ChristianLarsen@.discussions.microsoft.com> wrote in
message news:608EB056-430E-44A2-AD02-1621CA41FC3F@.microsoft.com...
> Hi all.
> How do i get a different color on odd rows in a table or matrix?
> /Chrsitian
TableGreenBar.rdl
================================================================================<?xml version="1.0" encoding="utf-8"?>
<Report
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition"
xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<RightMargin>1in</RightMargin>
<Body>
<ReportItems>
<Table Name="table1">
<Height>1in</Height>
<Style />
<Header>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="textbox4">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>11</ZIndex>
<rd:DefaultName>textbox4</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>Country</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox1">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>10</ZIndex>
<rd:DefaultName>textbox1</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>Company Name</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox3">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>9</ZIndex>
<rd:DefaultName>textbox3</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
</Header>
<Details>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="textbox2">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>2</ZIndex>
<rd:DefaultName>textbox2</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="CompanyName">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<BackgroundColor>=iif(RowNumber(Nothing) Mod 2,
"PaleGreen", "White")</BackgroundColor>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<rd:DefaultName>CompanyName</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!CompanyName.Value</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox6">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<rd:DefaultName>textbox6</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
</Details>
<DataSetName>Northwind</DataSetName>
<TableGroups>
<TableGroup>
<Header>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="Country">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<BackgroundColor>=iif(RunningValue(Fields!Country.Value,CountDistinct,Nothing)
Mod 2, "Cornsilk", "White")</BackgroundColor>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>8</ZIndex>
<rd:DefaultName>Country</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!Country.Value</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox11">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>7</ZIndex>
<rd:DefaultName>textbox11</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox12">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>6</ZIndex>
<rd:DefaultName>textbox12</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
<RepeatOnNewPage>true</RepeatOnNewPage>
</Header>
<Grouping Name="CountryGroup">
<GroupExpressions>
<GroupExpression>=Fields!Country.Value</GroupExpression>
</GroupExpressions>
</Grouping>
</TableGroup>
</TableGroups>
<Footer>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="textbox7">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>5</ZIndex>
<rd:DefaultName>textbox7</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox8">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>4</ZIndex>
<rd:DefaultName>textbox8</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox9">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>3</ZIndex>
<rd:DefaultName>textbox9</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
</Footer>
<TableColumns>
<TableColumn>
<Width>1.66667in</Width>
</TableColumn>
<TableColumn>
<Width>1.66667in</Width>
</TableColumn>
<TableColumn>
<Width>1.66667in</Width>
</TableColumn>
</TableColumns>
</Table>
</ReportItems>
<Style />
<Height>1.875in</Height>
</Body>
<TopMargin>1in</TopMargin>
<DataSources>
<DataSource Name="Northwind">
<rd:DataSourceID>32d95cbf-5e5b-4fb3-a37a-39b9506b8c80</rd:DataSourceID>
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>data source=localhost;initial
catalog=Northwind</ConnectString>
<IntegratedSecurity>true</IntegratedSecurity>
</ConnectionProperties>
</DataSource>
</DataSources>
<Width>5in</Width>
<DataSets>
<DataSet Name="Northwind">
<Fields>
<Field Name="CustomerID">
<DataField>CustomerID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="CompanyName">
<DataField>CompanyName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="ContactName">
<DataField>ContactName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="ContactTitle">
<DataField>ContactTitle</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Address">
<DataField>Address</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="City">
<DataField>City</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Region">
<DataField>Region</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="PostalCode">
<DataField>PostalCode</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Country">
<DataField>Country</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Phone">
<DataField>Phone</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Fax">
<DataField>Fax</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>Northwind</DataSourceName>
<CommandText>SELECT *
FROM Customers</CommandText>
<Timeout>30</Timeout>
</Query>
</DataSet>
</DataSets>
<LeftMargin>1in</LeftMargin>
<rd:SnapToGrid>true</rd:SnapToGrid>
<rd:DrawGrid>true</rd:DrawGrid>
<rd:ReportID>4792d607-5639-4c89-ac36-2794e9e78a74</rd:ReportID>
<BottomMargin>1in</BottomMargin>
</Report>
MatrixGreenBar.rdl
================================================================================<?xml version="1.0" encoding="utf-8"?>
<Report
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition"
xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<RightMargin>1in</RightMargin>
<Body>
<ReportItems>
<Matrix Name="matrix1">
<Corner>
<ReportItems>
<Textbox Name="textbox1">
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>4</ZIndex>
<rd:DefaultName>textbox1</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value />
</Textbox>
</ReportItems>
</Corner>
<Height>0.5in</Height>
<Style />
<MatrixRows>
<MatrixRow>
<MatrixCells>
<MatrixCell>
<ReportItems>
<Textbox Name="Qty">
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<BackgroundColor>=ReportItems!Color.Value</BackgroundColor>
<TextAlign>Right</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<rd:DefaultName>Qty</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Sum(Fields!Qty.Value)</Value>
</Textbox>
</ReportItems>
</MatrixCell>
</MatrixCells>
<Height>0.25in</Height>
</MatrixRow>
</MatrixRows>
<MatrixColumns>
<MatrixColumn>
<Width>0.875in</Width>
</MatrixColumn>
</MatrixColumns>
<DataSetName>DataSet1</DataSetName>
<ColumnGroupings>
<ColumnGrouping>
<DynamicColumns>
<Grouping Name="Category">
<GroupExpressions>
<GroupExpression>=Fields!CategoryName.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<ReportItems>
<Textbox Name="CategoryName">
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Right</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>3</ZIndex>
<rd:DefaultName>CategoryName</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!CategoryName.Value</Value>
</Textbox>
</ReportItems>
</DynamicColumns>
<Height>0.25in</Height>
</ColumnGrouping>
</ColumnGroupings>
<Width>2in</Width>
<Top>0.125in</Top>
<Left>0.125in</Left>
<RowGroupings>
<RowGrouping>
<DynamicRows>
<Grouping Name="Country">
<GroupExpressions>
<GroupExpression>=Fields!Country.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<ReportItems>
<Textbox Name="Country">
<Style>
<BorderStyle>
<Default>Solid</Default>
<Right>None</Right>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<BackgroundColor>=iif(RunningValue(Fields!Country.Value,CountDistinct,Nothing)
Mod 2, "AliceBlue", "White")</BackgroundColor>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>2</ZIndex>
<rd:DefaultName>Country</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!Country.Value & " " &
RunningValue(Fields!Country.Value,CountDistinct,Nothing)</Value>
</Textbox>
</ReportItems>
</DynamicRows>
<Width>1in</Width>
</RowGrouping>
<RowGrouping>
<DynamicRows>
<Grouping Name="Count">
<GroupExpressions>
<GroupExpression>=1</GroupExpression>
</GroupExpressions>
</Grouping>
<ReportItems>
<Textbox Name="Color">
<Style>
<BorderStyle>
<Default>Solid</Default>
<Left>None</Left>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<BackgroundColor>=Value</BackgroundColor>
<FontSize>1pt</FontSize>
<Color>=Value</Color>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<CanGrow>true</CanGrow>
<Value>=iif(RunningValue(Fields!Country.Value,CountDistinct,Nothing)
Mod 2, "AliceBlue", "White")</Value>
</Textbox>
</ReportItems>
</DynamicRows>
<Width>0.125in</Width>
</RowGrouping>
</RowGroupings>
</Matrix>
</ReportItems>
<Style />
<Height>3.25in</Height>
</Body>
<TopMargin>1in</TopMargin>
<DataSources>
<DataSource Name="Northwind">
<rd:DataSourceID>26f1bf87-1fa6-4e77-8d1a-81b0cd940403</rd:DataSourceID>
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>data source=.;initial
catalog=Northwind</ConnectString>
<IntegratedSecurity>true</IntegratedSecurity>
</ConnectionProperties>
</DataSource>
</DataSources>
<Code />
<Width>6.875in</Width>
<DataSets>
<DataSet Name="DataSet1">
<Fields>
<Field Name="Country">
<DataField>Country</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Qty">
<DataField>Qty</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="CategoryName">
<DataField>CategoryName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>Northwind</DataSourceName>
<CommandText>SELECT Customers.Country, SUM([Order
Details].Quantity) AS Qty, Categories.CategoryName
FROM Customers INNER JOIN
Orders ON Customers.CustomerID = Orders.CustomerID
INNER JOIN
[Order Details] ON Orders.OrderID = [Order
Details].OrderID INNER JOIN
Products ON [Order Details].ProductID =Products.ProductID INNER JOIN
Categories ON Products.CategoryID =Categories.CategoryID
GROUP BY Customers.Country, Categories.CategoryName</CommandText>
</Query>
</DataSet>
</DataSets>
<LeftMargin>1in</LeftMargin>
<rd:SnapToGrid>true</rd:SnapToGrid>
<rd:DrawGrid>true</rd:DrawGrid>
<Description />
<rd:ReportID>ab2c120b-3169-427d-8ad6-b8716f8c5101</rd:ReportID>
<BottomMargin>1in</BottomMargin>
</Report>

Different between ##table and #table regarding performance

hi
also i want to know what have more performance : a table variable or a
temporary table in a stored procedure
the rows in the tables are approx. 1000
thanks michelINF: Frequently Asked Questions - SQL Server 2000 - Table Variables
http://support.microsoft.com/?kbid=305977
AMB
"haenselmic" wrote:

> hi
> also i want to know what have more performance : a table variable or a
> temporary table in a stored procedure
> the rows in the tables are approx. 1000
> thanks michel|||"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:0E5B6748-F110-497E-ABE3-C9B90F6280FA@.microsoft.com...
> INF: Frequently Asked Questions - SQL Server 2000 - Table Variables
> http://support.microsoft.com/?kbid=305977
>
> AMB
> "haenselmic" wrote:
>
Also I have never found a valid use for an ##temp global temporary table.
David|||You'll generally get better performance from in-memory temporary tables as
long as they are fairly small. SQL Server will push the memory table to
tempdb in certain situations such as row count or available memory. There
are some limitations on indexing with in-memory temporary tables. BOL has a
good section on temporary tables and explains better than I can without
plagairism <g>.
## temporary tables are 'global' temporary tables and are cleaned up when
sql server recycles tempdb. # temporary tables are local to the current
batch and are removed when the batch has completed.
-TIm
"haenselmic" <haenselmic@.discussions.microsoft.com> wrote in message
news:273D07B3-0236-43DC-AEF6-8F6D25681AAA@.microsoft.com...
> hi
> also i want to know what have more performance : a table variable or a
> temporary table in a stored procedure
> the rows in the tables are approx. 1000
> thanks michel|||I have used them a couple of times. It has been a while. From what I can
remember we had to dynamically build several sql statements, insert them
into one (##temporary) table and then perform some data manipulation and
retrieval from the ##table.
Keith Kratochvil
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:egT2TU1eGHA.5088@.TK2MSFTNGP02.phx.gbl...
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in
> message news:0E5B6748-F110-497E-ABE3-C9B90F6280FA@.microsoft.com...
>
> Also I have never found a valid use for an ##temp global temporary table.
> David
>|||Global temporary tables are cleaned up as follows (according to BOL):
"Global temporary tables are automatically dropped when the session
that created the table ends and all other tasks have stopped
referencing them. The association between a task and a table is
maintained only for the life of a single Transact-SQL statement. This
means that a global temporary table is dropped at the completion of the
last Transact-SQL statement that was actively referencing the table
when the creating session ended."
I didn't think that tempdb recycled to those rules, I thought it was
recreated upon startup only.
Cheers
Will|||"Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
news:ey10gf1eGHA.2416@.TK2MSFTNGP03.phx.gbl...
>I have used them a couple of times. It has been a while. From what I can
>remember we had to dynamically build several sql statements, insert them
>into one (##temporary) table and then perform some data manipulation and
>retrieval from the ##table.
>
But if you didn't retrieve them in another session, a #table would have
sufficed.
David|||"Tim Dot NoSpam" <Tim.NoSpam@.hughes.net> wrote in message
news:%23Il8tY1eGHA.1208@.TK2MSFTNGP02.phx.gbl...
> You'll generally get better performance from in-memory temporary tables as
> long as they are fairly small. SQL Server will push the memory table to
> tempdb in certain situations such as row count or available memory. There
> are some limitations on indexing with in-memory temporary tables. BOL has
> a good section on temporary tables and explains better than I can without
> plagairism <g>.
> ## temporary tables are 'global' temporary tables and are cleaned up when
> sql server recycles tempdb. # temporary tables are local to the current
> batch and are removed when the batch has completed.
>
#table temp tables live for the life of the connection, not the batch.
There is an exeption for #temp tables created inside stored procedures.
They are automatically dropped after the stored procedure is invoked.
David|||As I mentioned, it has been a while. I don't remember all the gory details,
but the global temp table seemed like the best solution (or perhaps the only
solution) at the time.
Keith Kratochvil
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:uGhk1E2eGHA.2188@.TK2MSFTNGP05.phx.gbl...
> "Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
> news:ey10gf1eGHA.2416@.TK2MSFTNGP03.phx.gbl...
> But if you didn't retrieve them in another session, a #table would have
> sufficed.
> David
>|||Has anyone ever used global temporary tables (##temp)? They seem awfully
useless.
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:uGhk1E2eGHA.2188@.TK2MSFTNGP05.phx.gbl...
> "Keith Kratochvil" <sqlguy.back2u@.comcast.net> wrote in message
> news:ey10gf1eGHA.2416@.TK2MSFTNGP03.phx.gbl...
> But if you didn't retrieve them in another session, a #table would have
> sufficed.
> David
>