Showing posts with label contain. Show all posts
Showing posts with label contain. Show all posts

Wednesday, March 28, 2012

Grouping on multiple datasets - ANY suggestions

I have a report with two datasets, DS1 and DS2, which contain the same data fields, but with different values. Like so:

DS1 = sales
salesperson sale_number amount
John Smith 1 $100
John Smith 2 $105
Mary Jane 3 $98
John Smith 4 $275
Mary Jane 5 $92

DS2 = sales with price overrides
salesperson sale_number amount
John Smith 1 $100
Mary Jane 3 $98
Mary Jane 5 $92

Now what I want to do is see how the salespeople are doing. I can use either dataset and get great results independently:

Sales Results:
Salesperson Number of Sales Total Amount
John Smith 3 $480
Mary Jane 2 $190

or

Sales results with price overrides:
Salesperson NumSales with Over Total Amount
John Smith 1 $480
Mary Jane 2 $190

Now what I really want to do is a combo table like so:
Salesperson NumSales with Over Number of Sales %Overrides
John Smith 1 3 33.3%
Mary Jane 2 2 100%

I can not figure out how to do this. If I create a table that has DS1 as its datasource, I need to access DS2 for a count. So I try this for the NumSales with Over:

= count((Fields!sale_number.Value,"DS2"))

This just repeates the total number of sales in DS2, which is 3, for each line; not separating them out by salesperson.

If I try something fancier such as:

=count((Fields!sale_number.Value,"DS2", (Fields!Salesperson.Value,"DS2") like =(Fields!Salesperson.Value))

The report won't even run.

I want to do something along those lines. Does anyone have any ideas how to do this? I've considered subqueries to use salesperson as a filter, but the datasets are so large that the reports end up taking forever to run. I've tried using iif, but it doesn't seem to like using a field from a second dataset. I even tried to use the embedded VB code box to write a function, but then I couldn't pass the full array from the secondary dataset to the function (I could pass it from DS1, but not DS2).

I know this is incredibly simple, but this noob can't figure it out. If anyone has any suggestions I would deeply appreciate it.

Thank you,

cmk8895Joining datasets at a report level is not currently supported. It is on the wish list for a next release. Why don't you create the combo dataset at the data source level?

Friday, March 9, 2012

Group by problem!

I need to use Group By on a text column that contain numeric data in
different format.
For example, column "terminalID" can contain "0123" and '123' pointing to
the same terminal.
Group by treats these as 2 different groups.
I used CAST (terminalID as INT) as 'terminalID' in SELECT but still got the
same problem since I cannot use CAST in Group By clause.
Any help is greatly appreciated!
Bill
select CAST(terminalID as INT) as terminalID
from table A
group by terminalID> I used CAST (terminalID as INT) as 'terminalID' in SELECT but still got
> the same problem since I cannot use CAST in Group By clause.
CAST is allowed in a GROUP BY clause. The example below should work,
assuming terminalID is always numeric.
SELECT CAST(terminalID AS int) AS terminalID
FROM MyTable
GROUP BY CAST(terminalID AS int)
Hope this helps.
Dan Guzman
SQL Server MVP
"Bill nguyen" <billn_nospam_please@.jaco.com> wrote in message
news:O3Ud$mBBGHA.1028@.TK2MSFTNGP11.phx.gbl...
>I need to use Group By on a text column that contain numeric data in
>different format.
> For example, column "terminalID" can contain "0123" and '123' pointing to
> the same terminal.
> Group by treats these as 2 different groups.
> I used CAST (terminalID as INT) as 'terminalID' in SELECT but still got
> the same problem since I cannot use CAST in Group By clause.
> Any help is greatly appreciated!
> Bill
>
> select CAST(terminalID as INT) as terminalID
> from table A
> group by terminalID
>
>|||>> I need to use Group By on a text column that contain numeric data in diff
erent format. <<
Well, that is realllllly screwed up! In the RDBMS model, unlike 1950's
COBOL, there is no formatting in the database. We have abstract data
types. Look at the possible Numeric data types in any basic book on
SQL.
Gee, those are strings and not numeric at all! This is sooo basic.
1) Find the moron that did this schema and kill him. It will greatly
improve data quality.
2) Now, decide if this column is a string or a numeric; change the
table to reflect this decision; add a CHECK() constraint mto enforce
the correct format. Go thru all of your code and clean it up.
3) Read any book on SQL programming.|||Sounds like it is possible that the text column has 0s for padding when it
is created. Prior to Casting perhaps you could use a substring or trim
function to clean up the data. You might have to put the data in a temp
table are requery it so that you query the clean stuff.
Keith
"Bill nguyen" <billn_nospam_please@.jaco.com> wrote in message
news:O3Ud$mBBGHA.1028@.TK2MSFTNGP11.phx.gbl...
>I need to use Group By on a text column that contain numeric data in
>different format.
> For example, column "terminalID" can contain "0123" and '123' pointing to
> the same terminal.
> Group by treats these as 2 different groups.
> I used CAST (terminalID as INT) as 'terminalID' in SELECT but still got
> the same problem since I cannot use CAST in Group By clause.
> Any help is greatly appreciated!
> Bill
>
> select CAST(terminalID as INT) as terminalID
> from table A
> group by terminalID
>
>|||Thank you all.
Dan's statement below solved the problem.
Celko's comments are seriously considered
Bill
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:uRKfgtBBGHA.240@.TK2MSFTNGP11.phx.gbl...
> CAST is allowed in a GROUP BY clause. The example below should work,
> assuming terminalID is always numeric.
> SELECT CAST(terminalID AS int) AS terminalID
> FROM MyTable
> GROUP BY CAST(terminalID AS int)
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Bill nguyen" <billn_nospam_please@.jaco.com> wrote in message
> news:O3Ud$mBBGHA.1028@.TK2MSFTNGP11.phx.gbl...
>

Wednesday, March 7, 2012

Group By Error Under SQL 2005

Our stored procedure throws the following error when running on 2005
w/compatibility set to 90, but not 80:
"Each GROUP BY expression must contain at least one column that is not an
outer reference. Severity 15, State 1, Procedure "procname", line 351"
The code in question is:
....
OR
(EXISTS (SELECT e.logical_seat_row, b.logical_seat_num, count(*)
FROM #ZoomSet e
WHERE e.logical_seat_num >= b.logical_seat_num
and e.logical_seat_num <= c.logical_seat_num
and e.bit_col & 64 = 64
and e.logical_seat_row = b.logical_seat_row
GROUP BY e.logical_seat_row, b.logical_seat_num
HAVING count(*) >= @.num_wc_ind))
)
.....
I've searched support.msft.com, as well as this newsgroup, and all of the
web, but can't find this error anywhere. Any ideas would be appreciated.
Thanks!
Steven Bras
Tessitura Network, Inc.>> Our stored procedure throws the following error when running on 2005 w/co
mpatibility set to 90, but not 80:: "Each GROUP BY expression must contain a
t least one column that is not an outer reference. Severity 15, State 1, Pr
ocedure "procname", line 35
1" <<
As best I can tell from the fragment posted, the code lookd fine from a
standards viewpoint (ignoring the bit operator crap). I would clean it
up for human use (one BETWEEN is easier to read and understand than two
comparisons) and see if that helps.
Since it is an EXISTS() predicate, use the * instead of a list; my
thought is that the engine might be trying to build the list when all
it needs to do is find is one row.
OR
(EXISTS (SELECT *
FROM #ZoomSet AS E
WHERE E.logical_seat_num
BETWEEN B.logical_seat_num
AND C.logical_seat_num
AND E.bit_col & 64 = 64
AND E.logical_seat_row = B.logical_seat_row
GROUP BY E.logical_seat_row, B.logical_seat_num
HAVING COUNT (*) >= @.num_wc_ind))
)
The other things are to re-write the whole query to get rid of the
temp table and the assembly language bit fiddling.
It looks like you are trying to find a block of vacant seats on the
same row. Ihave queries for that in SQL FOR SMARTIES which are
simpler.|||Thanks; I do appreciate your response and am a long-standing admirer of your
columns and books.
But why does the error now occur under 2005 where it didn't used to under
SQL 2000?
--
Steven Bras
Tessitura Network, Inc.
"--CELKO--" wrote:

351" <<
> As best I can tell from the fragment posted, the code lookd fine from a
> standards viewpoint (ignoring the bit operator crap). I would clean it
> up for human use (one BETWEEN is easier to read and understand than two
> comparisons) and see if that helps.
> Since it is an EXISTS() predicate, use the * instead of a list; my
> thought is that the engine might be trying to build the list when all
> it needs to do is find is one row.
> OR
> (EXISTS (SELECT *
> FROM #ZoomSet AS E
> WHERE E.logical_seat_num
> BETWEEN B.logical_seat_num
> AND C.logical_seat_num
> AND E.bit_col & 64 = 64
> AND E.logical_seat_row = B.logical_seat_row
> GROUP BY E.logical_seat_row, B.logical_seat_num
> HAVING COUNT (*) >= @.num_wc_ind))
> )
> The other things are to re-write the whole query to get rid of the
> temp table and the assembly language bit fiddling.
> It looks like you are trying to find a block of vacant seats on the
> same row. Ihave queries for that in SQL FOR SMARTIES which are
> simpler.
>|||> But why does the error now occur under 2005 where it didn't used to under
> SQL 2000?
In the Books Online topic 'sp_dbcmptlevel', it states the following:
Compatibility level setting of 80 A GROUP BY clause in a subquery that
references a column from the outer query succeeds.
Compatibility level setting of 90 A GROUP BY clause in a subquery that
references a column from the outer query returns an error as per the SQL
standard.
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
Download the latest version of Books Online from
http://www.microsoft.com/technet/pr...oads/books.mspx
"StevenBr" <sbras@.community.nospam> wrote in message
news:ACFBFA3A-8CAF-4875-A83F-38607B5BDC23@.microsoft.com...
> Thanks; I do appreciate your response and am a long-standing admirer of
> your
> columns and books.
> But why does the error now occur under 2005 where it didn't used to under
> SQL 2000?
> --
> Steven Bras
> Tessitura Network, Inc.
>
> "--CELKO--" wrote:
>|||n Mon, 26 Jun 2006 17:39:15 -0700, "Gail Erickson [MS]"
<gaile@.online.microsoft.com> wrote:

> In the Books Online topic 'sp_dbcmptlevel', it states the following:
>Compatibility level setting of 80 A GROUP BY clause in a subquery that
>references a column from the outer query succeeds.
>Compatibility level setting of 90 A GROUP BY clause in a subquery that
>references a column from the outer query returns an error as per the SQL
>standard.
Interesting.
It may also be worth pointing out why this would be so. Any reference
within the subquery that refers to the outer query is, for the purpose
of the subquery, a reference to a constant. And there is no reason to
include a constant in a GROUP BY list.
In the specific example posted:

>....
> OR
> (EXISTS (SELECT e.logical_seat_row, b.logical_seat_num, count(*)
> FROM #ZoomSet e
> WHERE e.logical_seat_num >= b.logical_seat_num
> and e.logical_seat_num <= c.logical_seat_num
> and e.bit_col & 64 = 64
> and e.logical_seat_row = b.logical_seat_row
> GROUP BY e.logical_seat_row, b.logical_seat_num
> HAVING count(*) >= @.num_wc_ind))
> )
>.....
it is the reference to b.logical_seat_num in the GROUP BY that is
redundant, since there can be only one value for any given evaluation
of the subquery. But we can go farther and observe that since
e.logical_seat_row = b.logical_seat_row, the reference to
e.logical_seat_row in the GROUP BY is also redundant.
Which means the entire GROUP BY clause is not required, as they
resolve to a single row, and since (as has already been pointed out)
the SELECT list for an EXISTS subquery should be *, the GROUP BY
should be redundant... BUT WAIT! Will it be legal to have a HAVING
clause reference an aggregate expression COUNT when the select list is
an *? Good question, I'm not sure.
--Quick test in 2000 and 2005, using system tables, demonstrates that
--it works!
select *
from sysobjects
where exists
(select * from syscolumns
where syscolumns.id = sysobjects.id
having count(*) > 30)
But it still looks funny to my sensitive nature. I think it might be
safer to rewrite without the EXISTS:
OR
(@.num_wc_ind <=
(SELECT count(*)
FROM #ZoomSet e
WHERE e.logical_seat_num >= b.logical_seat_num
and e.logical_seat_num <= c.logical_seat_num
and e.bit_col & 64 = 64
and e.logical_seat_row = b.logical_seat_row)
)
Roy Harvey
Beacon Falls, CT|||Hi,
Just checking in to see if the suggestions were helpful. Please let us know
if you would like further assistance.
Have a great day!
+++++++++++++++++++++++++++
Charles Wang
Microsoft Online Partner Support
+++++++++++++++++++++++++++
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a w to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/te...erview/40010469
Others:
https://partner.microsoft.com/US/te...upportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/defaul...rnational.aspx.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

Sunday, February 26, 2012

group by date only

Hi all,
I have a field that has datetime datatype. its data contain hour and minute.
how can I select it and format it as only "mm/dd/yyyy"? I don't want hour
and minute. In short I want to group by date. Something like 1/1/2002 as a
group, 1/2/2003 as a group.
Thanks,
eguyWill something like this work?
USE Northwind
select convert(char(12), OrderDate, 101) date, count(*) NumOrders
from Orders
group by convert(char(12), OrderDate, 101)
order by 1
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"*eguy" <hstandit@.yahoo.com> wrote in message
news:#cfzlW7jDHA.1004@.TK2MSFTNGP09.phx.gbl...
> Hi all,
> I have a field that has datetime datatype. its data contain hour and
minute.
> how can I select it and format it as only "mm/dd/yyyy"? I don't want hour
> and minute. In short I want to group by date. Something like 1/1/2002 as a
> group, 1/2/2003 as a group.
> Thanks,
> eguy
>|||It works.
Thank you very much.
eguy
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:%236QJda7jDHA.2580@.TK2MSFTNGP10.phx.gbl...
> Will something like this work?
> USE Northwind
> select convert(char(12), OrderDate, 101) date, count(*) NumOrders
> from Orders
> group by convert(char(12), OrderDate, 101)
> order by 1
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "*eguy" <hstandit@.yahoo.com> wrote in message
> news:#cfzlW7jDHA.1004@.TK2MSFTNGP09.phx.gbl...
> >
> > Hi all,
> >
> > I have a field that has datetime datatype. its data contain hour and
> minute.
> > how can I select it and format it as only "mm/dd/yyyy"? I don't want
hour
> > and minute. In short I want to group by date. Something like 1/1/2002 as
a
> > group, 1/2/2003 as a group.
> > Thanks,
> >
> > eguy
> >
> >
>

GROUP BY Bit in Integer

I have a table where each row contain a unique individual and it's scrap code. The scrap code is an integer where each of the 32 bits represent a unique scrap cause and each individual may have more than one scrap cause.

As an example: the indidual may be both too heavy and too high

Lets say these two scrap causes are represented by bit 0 and bit 1.

That again converts to the integer value 1 and 2. If both bits are true the value of the integer for that row/individual is 3. I use a support table that contain each bit (representetd as an integer value) and a description.

ScrapCode(ScrapCode, Description)

with upto 32 rows.

With this it is easy to decode the scrap code for a selected individual into separate causes, but that is for one individual.
Now I would like to create a report that count codes based on the unique scrap codes in the scrap code table. In other words I would like to group by each bit in the integer.

Table(Id, date, ScrapCode)

Select Count(*) from Table

WHERE ScrapCode <> 0

Group By "Bit"

Any suggestions?

can u supply an example of the expected outcome.|||

One way to do it is to take advantage of the POWER function, the bitwise '&' operator and a table of numbers. I mocked up the data with this:

declare @.aTable table
( rid integer,
scrapCode integer
)

insert into @.aTable
select iter,
-1000000000 + 2147483646*dbo.rand()
from small_iterator (nolock)

The definition of the SMALL_ITERATOR and DBO.RAND() objects can be found here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1330536&SiteID=1

I computed the results with this:

Select iter-1 as [Cause],
Count(*) as[Cause Count]
from @.aTable
inner join small_iterator (nolock)
on iter <= 32
WHERE ScrapCode <> 0
and ( iter < 32 and
ScrapCode & Power (2, iter-1) > 0 or
iter = 32 and
ScrapCode < 0
)
group by iter-1
order by iter-1

/*
Cause Cause Count
-- --
0 16333
1 16494
...
30 16470
31 15336
*/

|||

Found it myself after some trial and error:

Code Snippet

SELECT v.ScrapCode, COUNT(p.Snr) AS NoOfScrap

FROM [table] p, [ScrapCodes] v

WHERE p.date > '2007-04-20'

AND p.Scrapcode <> 0

AND p.ScrapCode & v.ScrapCode <> 0

GROUP BY v.ScrapCode

Output:

1 15

2 250

4 5

8 98

512 23

....

Friday, February 24, 2012

Group and subreport

Hi,
I have a report and I have defined a group in it.
both the group header and group footer has some information the detail section contain two subreports.
My requirement is that if there are more than 10 records in any of the subreport then only first 10 records will be displayed on each page along withh the group header and group footer. Somhow I managed to print the 10 records on each page with group header; but I am not able to get the footer on each page!!
Is there any option avaliable for this type of scenario.

I am using Crystal Report XI with ASP.NET.Hey.

Did u put a 'New Page After' in the group header or detail section of your main report?
If, then remove them there and place them in the Group Footer section.

Do not use any of the 'New Page Before/After' feathures in ure sub-reports.

Hope this helps.