Showing posts with label quantity. Show all posts
Showing posts with label quantity. Show all posts

Wednesday, March 28, 2012

Having condition

I have query:
SELECT name,company,sum(quantity) as quantity from table
GROUP BY name,company WITH ROLLUP HAVING name is not null
But in result set I get also resulting rows with name is null:
name company quantity
--
NULL NULL 100
NULL company1 2
NULL company2 5
...
...
name 1 company1 2
...
Any idea why?
How can I remove summarazing rows with name is null in result set?
I thought that having should work?
regards,Simonwhere name is not null
Having is intended for filtering aggregate values, not column values.
Admittedly, I would have expected it to work anyway. Maybe the rollup is
affecting it. I don't generally have a use for rollup, so I'm not really
sure how it functions...
"simonZ" <simon.zupan@.studio-moderna.com> wrote in message
news:%23N4vH%23HZGHA.2136@.TK2MSFTNGP05.phx.gbl...
> I have query:
> SELECT name,company,sum(quantity) as quantity from table
> GROUP BY name,company WITH ROLLUP HAVING name is not null
> But in result set I get also resulting rows with name is null:
> name company quantity
> --
> NULL NULL 100
> NULL company1 2
> NULL company2 5
> ...
> ...
> name 1 company1 2
> ...
> Any idea why?
> How can I remove summarazing rows with name is null in result set?
> I thought that having should work?
> regards,Simon
>|||Hi,
Check WITH ROLLUP clause in BOL.
The number of summary rows in the result set is determined by the number of
columns included in the GROUP BY clause. Each operand (column) in the GROUP
BY clause is bound under the grouping NULL and grouping is applied to all
other operands (columns). Because CUBE returns every possible combination of
group and subgroup, the number of rows is the same, regardless of the order
in which the grouping columns are specified.
Tomasz B.
"Jim Underwood" wrote:

> where name is not null
> Having is intended for filtering aggregate values, not column values.
> Admittedly, I would have expected it to work anyway. Maybe the rollup is
> affecting it. I don't generally have a use for rollup, so I'm not really
> sure how it functions...
> "simonZ" <simon.zupan@.studio-moderna.com> wrote in message
> news:%23N4vH%23HZGHA.2136@.TK2MSFTNGP05.phx.gbl...
>
>|||Thanks. I looked it up after making the last post, and tested it out.
On SQL 2000 the having clause works fine with this same logic. Granted, my
tables are different, but the following excluded null values from the result
set.
select description, bogusID, count(*), sum(random_id) from my_table
group by description, bogusID with rollup
having description is not null.
If I remove the having, then I get back rows where description is null, with
the having these rows are excluded. However, in my test the having
description is not null also removed the grand summary at the end of the
report. This is as expected, and the grand summary row is there if I use
where instead of having.
"Tomasz Borawski" <TomaszBorawski@.discussions.microsoft.com> wrote in
message news:2E2D3DBB-EA47-4E7F-BBB5-73C86261AA95@.microsoft.com...
> Hi,
> Check WITH ROLLUP clause in BOL.
> The number of summary rows in the result set is determined by the number
of
> columns included in the GROUP BY clause. Each operand (column) in the
GROUP
> BY clause is bound under the grouping NULL and grouping is applied to all
> other operands (columns). Because CUBE returns every possible combination
of
> group and subgroup, the number of rows is the same, regardless of the
order
> in which the grouping columns are specified.
> Tomasz B.
> "Jim Underwood" wrote:
>
is
really|||I meant to ask in my last response...
What version of SQL Server are you using, and could you post table DDL and
the full query that you are executing. If what you already posted is the
complete query, then just say so.
"simonZ" <simon.zupan@.studio-moderna.com> wrote in message
news:%23N4vH%23HZGHA.2136@.TK2MSFTNGP05.phx.gbl...
> I have query:
> SELECT name,company,sum(quantity) as quantity from table
> GROUP BY name,company WITH ROLLUP HAVING name is not null
> But in result set I get also resulting rows with name is null:
> name company quantity
> --
> NULL NULL 100
> NULL company1 2
> NULL company2 5
> ...
> ...
> name 1 company1 2
> ...
> Any idea why?
> How can I remove summarazing rows with name is null in result set?
> I thought that having should work?
> regards,Simon
>|||The only reliable test you can make in HAVING with ROLLUP/CUBE
is based on the GROUPING(column) test.So in this example you can test
HAVING GROUPING([name])=0/1
HAVING GROUPING(company)=0/1
HAVING GROUPING([name])=0/1 and/or GROUPING(company)=0/1
0 will test for null,1 a non null if i remember:)
Of course you make as complex a HAVING as you want using the GROUPING()
statements ie.
GROUPING([name])+GROUPING(company)=0
Of course the big implication of all this is that a temp table or derived
table
must be used for aggregate testing.Silly:)
"simonZ" <simon.zupan@.studio-moderna.com> wrote in message
news:%23N4vH%23HZGHA.2136@.TK2MSFTNGP05.phx.gbl...
>I have query:
> SELECT name,company,sum(quantity) as quantity from table
> GROUP BY name,company WITH ROLLUP HAVING name is not null
> But in result set I get also resulting rows with name is null:
> name company quantity
> --
> NULL NULL 100
> NULL company1 2
> NULL company2 5
> ...
> ...
> name 1 company1 2
> ...
> Any idea why?
> How can I remove summarazing rows with name is null in result set?
> I thought that having should work?
> regards,Simon
>

Friday, March 9, 2012

Hardware - Multiple Instances of SQL in a cluster

Can anyone advise as to the best practices for installing mulitple instances
of SQL into a cluster? Specifically as to the harddrive quantity and
configuration.
I already have 1 instance in a cluster and need to add more to it. So, my
cluster already has a drive for OS (Mirrored), a drive for MSDTC (Mirrored),
a drive for the quorum (Mirrored) and a drive for the database and
transaction logs (Raid5) (these are not high usage, so 1 drive for db and
logs should be more than sufficient).
I obviously need to add more hard drives to the cluster, but how many per
instance? I assume that I don't need more drives for MSDTC? Howabout the
quorum - is that one per instance? or is it just the databses ?
Thanks
Setesh
You should think of each virtual server as a separate real server. Decide
the disk layout as you would any stand-alone server. It takes at least one
physical disk to 'anchor' the virtual server.
You only need one Quorum disk and one MSDTC instance per cluster.
Geoff N. Hiten
Microsoft SQL Server MVP
"Setesh" <setesh@.nospam.NO> wrote in message
news:e177C7fZFHA.2076@.TK2MSFTNGP15.phx.gbl...
> Can anyone advise as to the best practices for installing mulitple
> instances of SQL into a cluster? Specifically as to the harddrive
> quantity and configuration.
> I already have 1 instance in a cluster and need to add more to it. So, my
> cluster already has a drive for OS (Mirrored), a drive for MSDTC
> (Mirrored), a drive for the quorum (Mirrored) and a drive for the database
> and transaction logs (Raid5) (these are not high usage, so 1 drive for db
> and logs should be more than sufficient).
> I obviously need to add more hard drives to the cluster, but how many per
> instance? I assume that I don't need more drives for MSDTC? Howabout the
> quorum - is that one per instance? or is it just the databses ?
> Thanks
> Setesh
>
|||Setesh
Here is some good information on SQL Clustering and Instances. In short you
will need additional disks only for SQL. The cluster quorum is a single
resource that is created when you install the cluster. You also have to plan
for each node to be able to scale to acceptable performance if a node has to
run more than one instance if their is a failure.
http://msdn.microsoft.com/library/de...ar_cs_9i5u.asp
Also if your installing a Named instance of SQL 2000 on a Windows 2003
cluster you will need to follow this article, setup will fail everytime until
you do. I had to learn this the hard way , my loss is your gain...good
luck!
http://support.microsoft.com/?kbid=815431
Regards
CT
"Setesh" wrote:

> Can anyone advise as to the best practices for installing mulitple instances
> of SQL into a cluster? Specifically as to the harddrive quantity and
> configuration.
> I already have 1 instance in a cluster and need to add more to it. So, my
> cluster already has a drive for OS (Mirrored), a drive for MSDTC (Mirrored),
> a drive for the quorum (Mirrored) and a drive for the database and
> transaction logs (Raid5) (these are not high usage, so 1 drive for db and
> logs should be more than sufficient).
> I obviously need to add more hard drives to the cluster, but how many per
> instance? I assume that I don't need more drives for MSDTC? Howabout the
> quorum - is that one per instance? or is it just the databses ?
> Thanks
> Setesh
>
>
|||Thanks for the info guys, especially the info on installing a named instance
on a 2003 cluster - thats probably saved me hours of work
Cheers
S.
"Charles Tolento" <CharlesTolento@.discussions.microsoft.com> wrote in
message news:F696B9E9-FCB9-481A-8541-5CD4FFE666B7@.microsoft.com...[vbcol=seagreen]
> Setesh
> Here is some good information on SQL Clustering and Instances. In short
> you
> will need additional disks only for SQL. The cluster quorum is a single
> resource that is created when you install the cluster. You also have to
> plan
> for each node to be able to scale to acceptable performance if a node has
> to
> run more than one instance if their is a failure.
> http://msdn.microsoft.com/library/de...ar_cs_9i5u.asp
> Also if your installing a Named instance of SQL 2000 on a Windows 2003
> cluster you will need to follow this article, setup will fail everytime
> until
> you do. I had to learn this the hard way , my loss is your gain...good
> luck!
> http://support.microsoft.com/?kbid=815431
> Regards
> CT
> "Setesh" wrote:

Hardcode subtotal

Hello,

Can I hardcode matrix subtotal?

For instance, I want to hardcode "100%" in the following Sales report:

2007 Year

Quantity

Phones 21%

Notebooks 30%

Total 100%

Please don't ask me why I need to do that, it's a complex MDX query and the report is much more complex than I depicted.

I just need to statically write 100% in subtotal.

Write the following expression

Code Snippet

=100 & "%"

in the text box where u want to display 100%.

Best Regards,

Rajiv

|||

RajivDotNet wrote:

Write the following expression

Code Snippet

=100 & "%"

in the text box where u want to display 100%.

Best Regards,

Rajiv

I would just like to mention the InScope function. If you have a calculation in that column to determine the percentage, you can just add an IIf and InScope function to the expression to determine whether you are within the bounds of your row group, if you are within bounds then do your normal percentage calculation, if you are out of bounds then just return "100" (and use the code p0 in the Format property so that things are formatted correctly when exported to Excel).

|||

Dear Rajiv and Sluggy,

Thank you very much for your quick response.

Your approach worked!