Friday, March 30, 2012

How to exclude duplicate records from totals

My column figures are correct in my report, but duplicate values are being added to the totals.

I am using:

Format(Sum(Fields!ACEG_Contribution.Value), "C")

This is not a matrix report. I am using tables so it only has table headers and table footers.

How can I fix this? Please advise a-sap.

Thanx in advance for any assistance you can provide,

gb

Hi Gerry-

Not completly certain where your duplication is coming from - as per your description. If duplicate values are present in your data, you would want to use the DISTINCT clause in your query to filter duplicates.

If you have groupings in your table, and want to subtotal rather than grandtotal, you can use the scope argument on the SUM function to filter per group i.e. Sum(Fields!Value, "Group1)".

If you want to display duplicates, bu only sum the non-duplicates, you would need to have a separate query which uses the DISTINCT caluse, then create an expression in your table footer which does sum of second dataset. i.e. SUM(Fields!Value, "DataSet2")

Hope that helps,

Thanks, Jon

How to evaluate the performance of the sql server

Hi all,
How to evaluate the performance of the SQL server 2000?
Hope you can help.
EricIt depend of what area of performance that you are looking for. If you
are looking for database access or query performance, you can use
Profiler or examine the query execution plan.
If you want to see the server performance, you can use performance counter.
Eric wrote:
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric|||"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:24381665-3E5C-4554-84D7-B798402D8FF6@.microsoft.com...
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric
Brad McGehee put together a great article on this.
http://www.devarticles.com/c/a/SQL-...-
Audit/
Rick Sawtell
MCT, MCSD, MCDBA

How to evaluate the performance of the sql server

Hi all,
How to evaluate the performance of the SQL server 2000?
Hope you can help.
EricIt depend of what area of performance that you are looking for. If you
are looking for database access or query performance, you can use
Profiler or examine the query execution plan.
If you want to see the server performance, you can use performance counter.
Eric wrote:
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric|||"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:24381665-3E5C-4554-84D7-B798402D8FF6@.microsoft.com...
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric
Brad McGehee put together a great article on this.
http://www.devarticles.com/c/a/SQL-Server/How-to-Perform-a-SQL-Server-Performance-Audit/
Rick Sawtell
MCT, MCSD, MCDBAsql

Wednesday, March 28, 2012

How to evaluate the performance of the sql server

Hi all,
How to evaluate the performance of the SQL server 2000?
Hope you can help.
Eric
It depend of what area of performance that you are looking for. If you
are looking for database access or query performance, you can use
Profiler or examine the query execution plan.
If you want to see the server performance, you can use performance counter.
Eric wrote:
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric
|||"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:24381665-3E5C-4554-84D7-B798402D8FF6@.microsoft.com...
> Hi all,
> How to evaluate the performance of the SQL server 2000?
> Hope you can help.
> Eric
Brad McGehee put together a great article on this.
http://www.devarticles.com/c/a/SQL-S...ormance-Audit/
Rick Sawtell
MCT, MCSD, MCDBA

How to evaluate sum on change of group?

I have a data set that is grouped based on 2 fields, but the value of the set
that I want to add by Group 1 is the same data that repeats for the first
group.
Example:
Value Grp1 Grp2
================= 100 1 1
100 1 2
100 1 3
200 2 1
200 2 2
200 2 3
I want to get a total of Value, but only evaluate the total when Grp1
changes. Currently, when I use the Sum function, it adds all values, giving
me a total of 900. I need a way to take the value of '100' when Grp1 = 100,
and add it to the value of '200' when Grp1 = 2 to give me a total of 300.
In Crystal Reports, there was a method to evaluate a sum only on the change
of a particular group. Is there some similar method in Reporting Services to
achieve this?It is available in SSRS as well but you need to try it and see how far you
can use this solutions. it goes like this.
= RunningValue(Fields!field1.Value, Sum, <groupname>) so it evaluates to tat
particular group or the scope.
Amarnath
"Ben Shaffer" wrote:
> I have a data set that is grouped based on 2 fields, but the value of the set
> that I want to add by Group 1 is the same data that repeats for the first
> group.
> Example:
> Value Grp1 Grp2
> =================> 100 1 1
> 100 1 2
> 100 1 3
> 200 2 1
> 200 2 2
> 200 2 3
>
> I want to get a total of Value, but only evaluate the total when Grp1
> changes. Currently, when I use the Sum function, it adds all values, giving
> me a total of 900. I need a way to take the value of '100' when Grp1 = 100,
> and add it to the value of '200' when Grp1 = 2 to give me a total of 300.
> In Crystal Reports, there was a method to evaluate a sum only on the change
> of a particular group. Is there some similar method in Reporting Services to
> achieve this?
>|||Ben,
You could also use grouping on the report. You could put a group sum in
the group header or footer, and then a grand total or a count of the
groups in the table footer.
When you use a normal sum function in a group, it sums only the group.
-Josh
Ben Shaffer wrote:
> I have a data set that is grouped based on 2 fields, but the value of the set
> that I want to add by Group 1 is the same data that repeats for the first
> group.
> Example:
> Value Grp1 Grp2
> =================> 100 1 1
> 100 1 2
> 100 1 3
> 200 2 1
> 200 2 2
> 200 2 3
>
> I want to get a total of Value, but only evaluate the total when Grp1
> changes. Currently, when I use the Sum function, it adds all values, giving
> me a total of 900. I need a way to take the value of '100' when Grp1 = 100,
> and add it to the value of '200' when Grp1 = 2 to give me a total of 300.
> In Crystal Reports, there was a method to evaluate a sum only on the change
> of a particular group. Is there some similar method in Reporting Services to
> achieve this?|||Thanks for the reply. I've tried using the scope parameter of the aggregate
function, but get report compilation errors when I do so. What you've
suggested with the "RunningValue" function is essentially the same as using
the Sum function.
I oversimplified my data set to really show my problem. Here's a slightly
different version:
field1 Grp1 Grp2
=================100 1 1
100 1 1
100 1 1
100 1 2
100 1 3
On the footer for group 2, I can just show the most recent value of field1.
i.e. when grp2 changes, I just display =Fields!field1.Value instead of a sum
to get the value that I need to display.
However, when I try to create a Sum of the 1st field on the footer for group
1, I get the total of all values of field1.
i.e. =Sum(Fields!field1.Value) on the footer for group 1 yields a value of
500. What I want to get is for the sum to evaluate only when group 2
changes, to yield a value of 300.
I have tried using the scope parameter to the sum function to do this.
i.e. =Sum(Fields!field1.Value, "Grp2")
When I try this, I get a report compile error telling me that:
"The value expression for textbox 'x' has a scope parameter that is not
valid for an aggregate function. The scope parameter must be set to a string
constant that is equal to either the name of a containing group, the name of
a containing data region, or the name of a data set."
What I understand of the error message is that I can't set the scope of the
sum function to be based on a group that group 1 contains. That it has to be
set to a group that contains group 1 instead.
Am I using scope incorrectly? If this is the way that scope functions, then
the "scope" of the aggregate function must control when the running total
resets to zero, rather than controlling when the running total gets evaluated
(which is the functionality that I *need*).
It doesn't make sense that I wouldn't have this capability with MS Reporting
Services, as lesser reporting tools (such as Crystal and R&R) all provided
this kind of functionality with running totals in reports.
Further suggestions would be hugely appreciated.
"Amarnath" wrote:
> It is available in SSRS as well but you need to try it and see how far you
> can use this solutions. it goes like this.
> = RunningValue(Fields!field1.Value, Sum, <groupname>) so it evaluates to tat
> particular group or the scope.
> Amarnath
> "Ben Shaffer" wrote:
> > I have a data set that is grouped based on 2 fields, but the value of the set
> > that I want to add by Group 1 is the same data that repeats for the first
> > group.
> > Example:
> > Value Grp1 Grp2
> > =================> > 100 1 1
> > 100 1 2
> > 100 1 3
> > 200 2 1
> > 200 2 2
> > 200 2 3
> >
> >
> > I want to get a total of Value, but only evaluate the total when Grp1
> > changes. Currently, when I use the Sum function, it adds all values, giving
> > me a total of 900. I need a way to take the value of '100' when Grp1 = 100,
> > and add it to the value of '200' when Grp1 = 2 to give me a total of 300.
> >
> > In Crystal Reports, there was a method to evaluate a sum only on the change
> > of a particular group. Is there some similar method in Reporting Services to
> > achieve this?
> >|||Thanks for your reply, but I've already done this. I've better explained my
situation in a reply to Amarnath above. Further help in regard to that post
would be greatly appreciated. Thanks :)
"Josh" wrote:
> Ben,
> You could also use grouping on the report. You could put a group sum in
> the group header or footer, and then a grand total or a count of the
> groups in the table footer.
> When you use a normal sum function in a group, it sums only the group.
> -Josh|||This might be a dumb question, but I have to ask...
You said:
However, when I try to create a Sum of the 1st field on the footer for
group
1, I get the total of all values of field1.
i.e. =Sum(Fields!field1.Value) on the footer for group 1 yields a value
of
500. What I want to get is for the sum to evaluate only when group 2
changes, to yield a value of 300.
You are trying to sum Group 2 to get a sum of 300, but you are summing
in the footer of group 1 and getting 500. Can't you just sum in the
group 2 footer? That would give you 300, and you would only get the sum
(group footer) every time group 2 changes...
-Josh
Ben Shaffer wrote:
> Thanks for the reply. I've tried using the scope parameter of the aggregate
> function, but get report compilation errors when I do so. What you've
> suggested with the "RunningValue" function is essentially the same as using
> the Sum function.
> I oversimplified my data set to really show my problem. Here's a slightly
> different version:
> field1 Grp1 Grp2
> =================> 100 1 1
> 100 1 1
> 100 1 1
> 100 1 2
> 100 1 3
> On the footer for group 2, I can just show the most recent value of field1.
> i.e. when grp2 changes, I just display =Fields!field1.Value instead of a sum
> to get the value that I need to display.
> However, when I try to create a Sum of the 1st field on the footer for group
> 1, I get the total of all values of field1.
> i.e. =Sum(Fields!field1.Value) on the footer for group 1 yields a value of
> 500. What I want to get is for the sum to evaluate only when group 2
> changes, to yield a value of 300.
> I have tried using the scope parameter to the sum function to do this.
> i.e. =Sum(Fields!field1.Value, "Grp2")
> When I try this, I get a report compile error telling me that:
> "The value expression for textbox 'x' has a scope parameter that is not
> valid for an aggregate function. The scope parameter must be set to a string
> constant that is equal to either the name of a containing group, the name of
> a containing data region, or the name of a data set."
> What I understand of the error message is that I can't set the scope of the
> sum function to be based on a group that group 1 contains. That it has to be
> set to a group that contains group 1 instead.
> Am I using scope incorrectly? If this is the way that scope functions, then
> the "scope" of the aggregate function must control when the running total
> resets to zero, rather than controlling when the running total gets evaluated
> (which is the functionality that I *need*).
> It doesn't make sense that I wouldn't have this capability with MS Reporting
> Services, as lesser reporting tools (such as Crystal and R&R) all provided
> this kind of functionality with running totals in reports.
> Further suggestions would be hugely appreciated.
> "Amarnath" wrote:
> > It is available in SSRS as well but you need to try it and see how far you
> > can use this solutions. it goes like this.
> >
> > = RunningValue(Fields!field1.Value, Sum, <groupname>) so it evaluates to tat
> > particular group or the scope.
> >
> > Amarnath
> >
> > "Ben Shaffer" wrote:
> >
> > > I have a data set that is grouped based on 2 fields, but the value of the set
> > > that I want to add by Group 1 is the same data that repeats for the first
> > > group.
> > > Example:
> > > Value Grp1 Grp2
> > > =================> > > 100 1 1
> > > 100 1 2
> > > 100 1 3
> > > 200 2 1
> > > 200 2 2
> > > 200 2 3
> > >
> > >
> > > I want to get a total of Value, but only evaluate the total when Grp1
> > > changes. Currently, when I use the Sum function, it adds all values, giving
> > > me a total of 900. I need a way to take the value of '100' when Grp1 = 100,
> > > and add it to the value of '200' when Grp1 = 2 to give me a total of 300.
> > >
> > > In Crystal Reports, there was a method to evaluate a sum only on the change
> > > of a particular group. Is there some similar method in Reporting Services to
> > > achieve this?
> > >

How to eval() a variable to get a column name?

OK.. I've got a stored procedure I'm writing, which accepts an argument called @.statfield... let's say I want to use this variable as a literal part of a SQL statement, example:

select * from table1 where @.statfield = @.value

I want to do basically an eval(@.statfield) so if @.statfield is "key_id", then the select statement comes out:

select * from table1 where key_id = @.value

How can I do this?

Thanks!Originally posted by MDesigner
OK.. I've got a stored procedure I'm writing, which accepts an argument called @.statfield... let's say I want to use this variable as a literal part of a SQL statement, example:

select * from table1 where @.statfield = @.value

I want to do basically an eval(@.statfield) so if @.statfield is "key_id", then the select statement comes out:

select * from table1 where key_id = @.value

How can I do this?

Thanks!

One way would be to build dynamic sql and execute it

I copy/pasted the following from SQL Server help

Building Statements at Run Time

DECLARE @.SQLString NVARCHAR(500)

/* Set column list. CHAR(13) is a carriage return, line feed.*/
SET @.SQLString = N'SELECT FirstName, LastName, Title' + CHAR(13)

/* Set FROM clause with carriage return, line feed. */
SET @.SQLString = @.SQLString + N'FROM Employees' + CHAR(13)

/* Set WHERE clause. */
SET @.SQLString = @.SQLString + N'WHERE LastName LIKE ''D%'''

EXEC sp_executesql @.SQLString|||One problem:

my sql statement is:

select distinct @.stat = packing_shipping from cp_elements where campaign_id = 10

however, if I use execlsql to execute that, @.stat is in some kind of local scope...and is asking to be declared, even though it already is.

How do I get my @.stat return value?? I can't do

select @.stat = exec sp_executesql @.sql

nor this:

exec @.stat = sp_executesql @.sql

help!|||declare @.stat <data type>
exec sp_executesql @.sql, N'@.stat <data type> out', @.stat out

print @.stat|||Hm, that didn't work for some reason..

declare @.stat int

....

set @.sql = N'select distinct ' + @.statfield + N' from cp_elements where campaign_id = ' + convert(nvarchar, @.campaign_id)
exec sp_executesql @.sql, N'@.stat int out', @.stat out
set @.rc = @.@.rowcount
select @.stat

@.stat shows up as NULL for some reason. did I do something wrong here?|||nevermind. altered the SQL and it worked:

set @.sql = N'select distinct @.stat = ' + @.statfield + N' from cp_elements where campaign_id = ' + convert(nvarchar, @.campaign_id)

How to estimate SQL database growth when new fields are added?

I need help regarding calculation of database size growth. Here is my
query:
Q1 We have created two SQL databases, databaseA and databaseB; they are
mirror images of a databaseC which is a non - SQL database.
DatabaseB has been altered to accomodate 3-4 new fields. We need to
estimate how much databaseB grew by. Please note that number of rows
and tables have remained same for both databaseB and databaseC. What
would be the best estimation technique?
We tried database size, in properties but results are very weird.
Any suggestion would be highly appreciated.
Thank you,
Anjali
Use Windows Explorer, and compare DatabaseA files with DatabaseB files. The
File size difference (reported by the OS) should be a matter of subtraction.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162533985.274091.33370@.k70g2000cwa.googlegro ups.com...
>I need help regarding calculation of database size growth. Here is my
> query:
> Q1 We have created two SQL databases, databaseA and databaseB; they are
> mirror images of a databaseC which is a non - SQL database.
> DatabaseB has been altered to accomodate 3-4 new fields. We need to
> estimate how much databaseB grew by. Please note that number of rows
> and tables have remained same for both databaseB and databaseC. What
> would be the best estimation technique?
>
> We tried database size, in properties but results are very weird.
> Any suggestion would be highly appreciated.
> Thank you,
> Anjali
>
|||I am not sure i can see SQL database in windows explorer. I have
already checked database sizes through SQL enterprise manager, but i am
not satisfied with results.
Is there any other solution?
Arnie Rowland wrote:[vbcol=seagreen]
> Use Windows Explorer, and compare DatabaseA files with DatabaseB files. The
> File size difference (reported by the OS) should be a matter of subtraction.
> --
> Arnie Rowland, Ph.D.
> Westwood Consulting, Inc
> Most good judgment comes from experience.
> Most experience comes from bad judgment.
> - Anonymous
> You can't help someone get up a hill without getting a little closer to the
> top yourself.
> - H. Norman Schwarzkopf
>
> "Anjali" <anjali.bisht@.gmail.com> wrote in message
> news:1162533985.274091.33370@.k70g2000cwa.googlegro ups.com...
|||Of course you can see the database files using Windows Explorer. Unless you
don't have permissions to the OS level of the server. IF that is the
situation, then ask your admin for assistance.
You can calculate the 'estimated' size increase by adding the datatype
storage requirements for the four new fields, and multiplying that by the
total number of rows in the table. If any of the four new columns are
indexed, the effect of indexing is not included.
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Anjali" <anjali.bisht@.gmail.com> wrote in message
news:1162550620.309751.37790@.m7g2000cwm.googlegrou ps.com...
>I am not sure i can see SQL database in windows explorer. I have
> already checked database sizes through SQL enterprise manager, but i am
> not satisfied with results.
> Is there any other solution?
> Arnie Rowland wrote:
>