Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Thursday, March 29, 2012

Dynamic report with several datasources

Hello,

I am currently working with SQL 2005 Reporting Services and MS Visual studio 2005.

In my SQL server I have data about organizations, so that each organization's data is stored in an individual database.
In addition, the number of organizations/databases is variable. I know the number of organizations and the name of each one (that it agrees with the name of its database)
because there is a database (organizationsDB) with a table (organizationsTB) containing the list of the organizations.

So, It would be possible to create a report containing a summary of each organization? .... for example a table in which each row contains data of each organization.

Could you give me any ideas?

Thanks in advance!

You could probably do something with a stored procedure, temp tables and some dynamic sql... eg.

DECLARE @.sql as varchar(8000)

DECLARE @.mydbname

DECLARE @.tempTable TABLE

{
-- insert table schema for org summary here
}

-- insert cursor to populate each database name from the table

Set @.Sql = 'Insert into @.tempTable Select * from ' + @.mydbname + '.dbo.Mytable'

EXEC(@.Sql)

-- loop cursor

-- display on report.

Select * from @.tempTable

I'm not a fan of cursors but that should work.

cheers,

Andrew

|||

Hello,

I am trying the solution that Andrew proposed but I got this Error: Must declare the scalar variable @.tempTable

The stored procedure code is the following:

ALTER PROCEDURE [dbo].[usp_GetListOrganizations]

AS

BEGIN

SET NOCOUNT ON;

DECLARE @.sql as varchar(8000);

DECLARE @.mydbname as varchar(50);

DECLARE @.tempTable as TABLE(SumMaxSize bigint NOT NULL,SumActualSize bigint NOT NULL, NumberOfUsers int NOT NULL);

-- insert cursor to populate each database name from the table

Declare myCursor Cursor For SELECT DomainName FROM domainsDB.dbo.domainsTB

Open myCursor

Fetch Next From myCursor

Into @.mydbname

While @.@.FETCH_STATUS = 0

Begin

Set @.Sql = 'Insert into @.tempTable Select COUNT(MaxSize) AS SumMaxSize, COUNT(ActualSize) AS SumActualSize, COUNT(SamName) AS NumberOfUsers from [' + @.mydbname + '].[dbo].[Users]'

EXEC(@.Sql)

-- loop cursor

Fetch Next From myCursor

Into @.mydbname

End

Close myCursor

SELECT * FROM @.tempTable

END

what is wrong? Could you help me?

Thanks in advance!

|||

...I have proved to use sp_executesql too:

Set @.Sql = 'Insert into ' + @.tempTable + ' Select COUNT(MaxSize) AS SumMaxSize, COUNT(ActualSize) AS SumActualSize, COUNT(SamName) AS NumberOfUsers from [' + @.mydbname + '].[dbo].[Users]'

EXEC sp_executesql @.Sql, N'@.tempTable TABLE, @.mydbname varchar(50)', @.tempTable, @.mydbname

But result is 'Must declare the scalar variable @.tempTable' twice

Thanks!

|||

Unfortunately that won't work very well since it's running in a different memory space.

What about

INSERT INTO @.tempTable

EXEC(@.Sql)

where @.Sql is the dynamic select SQL you are working with?

Alternatively, you could use a physical table and some sort of common identifier like user id + datetime.

Hope this works. Also check syntax on @.tempTable declaration. Not sure if it is correct.

cheers,

Andrew

Tuesday, March 27, 2012

Dynamic query help SQL 2005

I'm having a problem in getting a dynamic query in a sp working and the
code is below so can someone please help me? It would be very much
appreciated.

Thanks
Girogio

------------

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[Search_Profile]
@.Country NVARCHAR(100) = null,
@.County NVARCHAR(100) = null,
@.Town NVARCHAR(100) = null,
@.AType bit,
@.PageIndex int,
@.NumRows int,
@.UsersCount int Output
AS
BEGIN

DECLARE @.where_clause NVARCHAR(500);

IF @.Country IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aCountry = "' + @.Country +
'"'
END

IF @.County IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aCounty = "' + @.County + '"'
END

IF @.Town IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aTown = "' + @.Town + '"'
END

IF @.AType IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND Independent = "' +
Convert(NVARCHAR, @.AType) + '"'
END

DECLARE @.Query1 NVARCHAR(1000);
SET @.Query1 = 'SELECT @.UsersCount=(SELECT COUNT(*) FROM CustomProfile
WHERE aActive = 1 ' + @.where_clause
exec(@.Query1)

DECLARE @.startRowIndex int;
SET @.startRowIndex = (@.PageIndex * @.NumRows) +1;

DECLARE @.Query2 NVARCHAR(1000);

SET @.Query2 = 'WITH UsersProfiles as (
SELECT ROW_NUMBER() OVER (ORDER BY t.apubName) as Row, t.UserId,
t.apubName, t.aCounty, t.aTown, u.UserName
FROM CustomProfile t, vw_aspnet_Users u
WHERE t.UserID = u.UserID AND aActive = 1 ' + @.where_clause

Declare @.Query3 NVARCHAR(1000)

SET @.Query3 = '
SELECT UserId, apubName, aCounty, aTown, UserName
FROM ' + @.Query2 +
' WHERE Row BETWEEN ' + Convert(NVARCHAR, @.startRowIndex) + ' AND ' +
Convert(NVARCHAR, @.startRowIndex+@.NumRows-1)

exec(@.Query3)

END(george_Martinho@.hotmail.com) writes:
> I'm having a problem in getting a dynamic query in a sp working and the
> code is below so can someone please help me? It would be very much
> appreciated.

I certainly helps if you are more specific about what your problems
are. The one thing I caught at a glance is that you are using " as a
string delimiter. This is possible if QUOTED_IDENTIFIER is off, but
there is functionality that requires this setting to be on, so don't
do that.

Check out my article about dynamic search conditions on
http://www.sommarskog.se/dyn-search.html. There are some examples
that very similar to what you are doing.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Hi Girogio,

One problem I noticed is that the first time (actually everytime) you try to
set @.Where_Clause, It will always set @.Where_Clause to Null. Since
@.Where_Clause is Null to begin with.

Try This

DECLARE @.where_clause NVARCHAR(500);

Set @.where_clause = '' -- <New Line

--....Other Stuff as before

I didn't test this but I hope it helps.

-Dick Christoph
<george_Martinho@.hotmail.com> wrote in message
news:1139838631.991677.194800@.g47g2000cwa.googlegr oups.com...
> I'm having a problem in getting a dynamic query in a sp working and the
> code is below so can someone please help me? It would be very much
> appreciated.
> Thanks
> Girogio
> ------------
> set ANSI_NULLS ON
> set QUOTED_IDENTIFIER ON
> go
>
> ALTER PROCEDURE [dbo].[Search_Profile]
> @.Country NVARCHAR(100) = null,
> @.County NVARCHAR(100) = null,
> @.Town NVARCHAR(100) = null,
> @.AType bit,
> @.PageIndex int,
> @.NumRows int,
> @.UsersCount int Output
> AS
> BEGIN
> DECLARE @.where_clause NVARCHAR(500);
> IF @.Country IS NOT NULL
> BEGIN
> SET @.where_clause = @.where_clause + ' AND aCountry = "' + @.Country +
> '"'
> END
> IF @.County IS NOT NULL
> BEGIN
> SET @.where_clause = @.where_clause + ' AND aCounty = "' + @.County + '"'
> END
> IF @.Town IS NOT NULL
> BEGIN
> SET @.where_clause = @.where_clause + ' AND aTown = "' + @.Town + '"'
> END
> IF @.AType IS NOT NULL
> BEGIN
> SET @.where_clause = @.where_clause + ' AND Independent = "' +
> Convert(NVARCHAR, @.AType) + '"'
> END
>
> DECLARE @.Query1 NVARCHAR(1000);
> SET @.Query1 = 'SELECT @.UsersCount=(SELECT COUNT(*) FROM CustomProfile
> WHERE aActive = 1 ' + @.where_clause
> exec(@.Query1)
> DECLARE @.startRowIndex int;
> SET @.startRowIndex = (@.PageIndex * @.NumRows) +1;
> DECLARE @.Query2 NVARCHAR(1000);
> SET @.Query2 = 'WITH UsersProfiles as (
> SELECT ROW_NUMBER() OVER (ORDER BY t.apubName) as Row, t.UserId,
> t.apubName, t.aCounty, t.aTown, u.UserName
> FROM CustomProfile t, vw_aspnet_Users u
> WHERE t.UserID = u.UserID AND aActive = 1 ' + @.where_clause
> Declare @.Query3 NVARCHAR(1000)
> SET @.Query3 = '
> SELECT UserId, apubName, aCounty, aTown, UserName
> FROM ' + @.Query2 +
> ' WHERE Row BETWEEN ' + Convert(NVARCHAR, @.startRowIndex) + ' AND ' +
> Convert(NVARCHAR, @.startRowIndex+@.NumRows-1)
> exec(@.Query3)
> END

Dynamic query help

I'm having a problem in getting a dynamic query in a sp working and the
code is below so can someone please help me? It would be very much
appreciated.
Thanks
Girogio
---
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[Search_Profile]
@.Country NVARCHAR(100) = null,
@.County NVARCHAR(100) = null,
@.Town NVARCHAR(100) = null,
@.AType bit,
@.PageIndex int,
@.NumRows int,
@.UsersCount int Output
AS
BEGIN
DECLARE @.where_clause NVARCHAR(500);
IF @.Country IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aCountry = "' + @.Country +
'"'
END
IF @.County IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aCounty = "' + @.County + '"'
END
IF @.Town IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND aTown = "' + @.Town + '"'
END
IF @.AType IS NOT NULL
BEGIN
SET @.where_clause = @.where_clause + ' AND Independent = "' +
Convert(NVARCHAR, @.AType) + '"'
END
DECLARE @.Query1 NVARCHAR(1000);
SET @.Query1 = 'SELECT @.UsersCount=(SELECT COUNT(*) FROM CustomProfile
WHERE aActive = 1 ' + @.where_clause
exec(@.Query1)
DECLARE @.startRowIndex int;
SET @.startRowIndex = (@.PageIndex * @.NumRows) +1;
DECLARE @.Query2 NVARCHAR(1000);
SET @.Query2 = 'WITH UsersProfiles as (
SELECT ROW_NUMBER() OVER (ORDER BY t.apubName) as Row, t.UserId,
t.apubName, t.aCounty, t.aTown, u.UserName
FROM CustomProfile t, vw_aspnet_Users u
WHERE t.UserID = u.UserID AND aActive = 1 ' + @.where_clause
Declare @.Query3 NVARCHAR(1000)
SET @.Query3 = '
SELECT UserId, apubName, aCounty, aTown, UserName
FROM ' + @.Query2 +
' WHERE Row BETWEEN ' + Convert(NVARCHAR, @.startRowIndex) + ' AND ' +
Convert(NVARCHAR, @.startRowIndex+@.NumRows-1)
exec(@.Query3)
ENDThere are lots of problems with your dynamic SQL,
@.where_clause is always NULL (NULL + string gives NULL)
@.UsersCount will never get set as it is in the wrong scope
Your CTE should be at the start of the statement, not the middle
You should be able to avoid dynamic SQL by doing
something like this.
ALTER PROCEDURE [dbo].[Search_Profile]
@.Country NVARCHAR(100) = null,
@.County NVARCHAR(100) = null,
@.Town NVARCHAR(100) = null,
@.AType bit,
@.PageIndex int,
@.NumRows int,
@.UsersCount int Output
AS
BEGIN
SET NOCOUNT ON
SELECT @.UsersCount=COUNT(*) FROM CustomProfile
WHERE aActive = 1
AND (@.Country IS NULL OR aCountry=@.Country)
AND (@.County IS NULL OR aCounty=@.County)
AND (@.Town IS NULL OR aTown=@.Town)
AND (@.AType IS NULL OR Independent=@.AType)
DECLARE @.startRowIndex int;
SET @.startRowIndex = (@.PageIndex * @.NumRows) + 1;
WITH UsersProfiles as (
SELECT ROW_NUMBER() OVER (ORDER BY t.apubName) as Row,
t.UserId, t.apubName, t.aCounty, t.aTown, u.UserName
FROM CustomProfile t, vw_aspnet_Users u
WHERE t.UserID = u.UserID AND aActive = 1
AND (@.Country IS NULL OR aCountry=@.Country)
AND (@.County IS NULL OR aCounty=@.County)
AND (@.Town IS NULL OR aTown=@.Town)
AND (@.AType IS NULL OR Independent=@.AType)
)
SELECT UserId, apubName, aCounty, aTown, UserName
FROM UsersProfiles
WHERE Row BETWEEN @.startRowIndex AND @.startRowIndex+@.NumRows-1
END

Thursday, March 22, 2012

Dynamic Page Headers

Ok, I'm working on a report, it will give a list of pet charts, the
main page will have all the data for the pet, and each pet visits an
office for a checkup or problem. Each visit will be on its own page. I
currently have this working with a sub report. What I need is the data
from the pet to show up in the page header for each page on the
report. The report will be run for several pets at a time. So is there
any way to get data from the currently displayed list item into the
page header?sorry for the double post, groups.google.com gave me a network error
to start with.
On Sep 19, 1:29 pm, "lance.sanc...@.gmail.com"
<lance.sanc...@.gmail.com> wrote:
> Ok, I'm working on a report, it will give a list of pet charts, the
> main page will have all the data for the pet, and each pet visits an
> office for a checkup or problem. Each visit will be on its own page. I
> currently have this working with a sub report. What I need is the data
> from the pet to show up in the page header for each page on the
> report. The report will be run for several pets at a time. So is there
> any way to get data from the currently displayed list item into the
> page header?

Dynamic Page Breaks

Hi everyone,

This is my first thread. I have been working with Reporting Services and love the way I can change the Groupings and Sortings on the fly. I need to be able to dynamically change which Groupings have a Page Break either before or after as well. There is no expression to enter for the Page break attributes however!

Does anyone know of a way to dynamically change the Page break attributes at run time?

Thanks,

Randy

No, dynamically changing page breaks is not supported.|||

is there any alternative fang?

Like having two groups for the same field with one page break and one with no page break and hiding or changing the expression of a group based on condition!

|||you need to create a dummy group with "page break at end" true for this and the expression for group will be set according to parameter value

like if user has selected "Yes" then set group expression

=iif(parametrvalue=yes,<fieldname-day>,1)

try this, it should work.

Dynamic Page Breaks

Hi everyone,

This is my first thread. I have been working with Reporting Services and love the way I can change the Groupings and Sortings on the fly. I need to be able to dynamically change which Groupings have a Page Break either before or after as well. There is no expression to enter for the Page break attributes however!

Does anyone know of a way to dynamically change the Page break attributes at run time?

Thanks,

Randy

No, dynamically changing page breaks is not supported.|||

is there any alternative fang?

Like having two groups for the same field with one page break and one with no page break and hiding or changing the expression of a group based on condition!

|||you need to create a dummy group with "page break at end" true for this and the expression for group will be set according to parameter value

like if user has selected "Yes" then set group expression

=iif(parametrvalue=yes,<fieldname-day>,1)

try this, it should work.

Wednesday, March 21, 2012

Dynamic Message Box In Report

Hello Sir,

I m working in Microsoft SQL Server Analysis Services Designer
Version 9.00.1399.00 for creating reports .

Now, I m facing a problem to view a run time dialog box at time of my report.
Means ,
In my report procedure , i have fired 2 delete queries after firing of these queries i wanna show a message box with Message "Some Records are Deleted". and one Ok Button !!

and after showing this dialog box i wanna view my report output !!

The procedure of my report is :
--
create procedure MyTemp
as

-- Query1
delete from myTempTable1 where Id = 5

-- Query2
delete from myTempTable2 where Id = 10

-- After exectuing above two queries Query1 and Query2.
-- here i want to view amessage dialog box with message "Some Records are Deleted"

select Id, name from myTempTable1,myTempTable2
--

So, how can i do this !!
I will change in my proceudre or report !!
Please suggest me about solution of this problem .

If u dont have any solution regaring this then please suggest me where i will get
the solution of this problem .

There is no messagebox in reporting services. Yout will have to give the results back as a dataset and render it in the report if your want to display it.

Jens K. Suessmeyer

http://www.sqlserver2005.de

Dynamic menu ?

Hi all,
I'm working with a report in Reporting Services 2005 and I have a problem
that I don't know how to solve.
In my report I have two drop down menus(not mvp) where the first one holds
countries. The second one holds
cities. I want the second menu to be dynamic, i.e. only show cities for the
country I selected in the first menu.
Is this possible to do in RS?
Thanks!Yes, it is. You are talking about cascading parameters.
Create your country parameter and define its datasource. This can be
either a value list or a dataset.
Create a cities dataset using the country parameter in a where clause.
Create your city parameter and define its datasource as a the dataset
that you just created. The "cascading" effect will happen automatically
because the city drop-down cannot be populated until you assign a value
to the country parameter.
Does this explanation make sense?
-Josh
Malin Davidsson (at) wrote:
> Hi all,
> I'm working with a report in Reporting Services 2005 and I have a problem
> that I don't know how to solve.
> In my report I have two drop down menus(not mvp) where the first one holds
> countries. The second one holds
> cities. I want the second menu to be dynamic, i.e. only show cities for the
> country I selected in the first menu.
> Is this possible to do in RS?
> Thanks!|||If you can populate the second list using SQL based on a parameter from the
first list, it should be possible I'd think. I haven't tried though.
Randall Arnold
"Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
news:eSpYAgM2GHA.2176@.TK2MSFTNGP04.phx.gbl...
> Hi all,
> I'm working with a report in Reporting Services 2005 and I have a problem
> that I don't know how to solve.
> In my report I have two drop down menus(not mvp) where the first one holds
> countries. The second one holds
> cities. I want the second menu to be dynamic, i.e. only show cities for
> the country I selected in the first menu.
> Is this possible to do in RS?
> Thanks!
>|||Thank you, that solved the problem =)
<bell.joshua@.gmail.com> wrote in message
news:1158330681.278038.205980@.k70g2000cwa.googlegroups.com...
> Yes, it is. You are talking about cascading parameters.
> Create your country parameter and define its datasource. This can be
> either a value list or a dataset.
> Create a cities dataset using the country parameter in a where clause.
> Create your city parameter and define its datasource as a the dataset
> that you just created. The "cascading" effect will happen automatically
> because the city drop-down cannot be populated until you assign a value
> to the country parameter.
> Does this explanation make sense?
> -Josh
>
> Malin Davidsson (at) wrote:
>> Hi all,
>> I'm working with a report in Reporting Services 2005 and I have a problem
>> that I don't know how to solve.
>> In my report I have two drop down menus(not mvp) where the first one
>> holds
>> countries. The second one holds
>> cities. I want the second menu to be dynamic, i.e. only show cities for
>> the
>> country I selected in the first menu.
>> Is this possible to do in RS?
>> Thanks!
>

Dynamic Members Security

Hi All,
I have a working solution with user-defined security. When user connects to a cube, a list with allowed members is created(retrieved from table) and returned as set to AS. Everything works fine.

Problem is that members are retrieved only at connection time. When I change my table with allowed members later, I would like to force AS to re-read this information again. Of course I can restart AS service or do full process of cube.

Does anybody have an idea?

Thanks,
Radim

Have you tried just reprocessing the dimension affected? What are the specifics of the solution?

|||That's very correct. Processing is possible solution but since I have many concurent users I didn't want to disrupt them. But yesterday I played with it more and I discovered that it's only necessary to do Process index. That's enough to force re-read of allowed members.

Thanks for contribution.

Radim

Dynamic MDX Query

I am working on SRS 2005 report and need to calculate measures based on parameters. The new great feature of SRS2005 which allows to use parameters in MDX query unfortunately does not work in inner query. For example I am building 4 time sets based on specified date ranges and then calculate summary for each time set. So query looks like this:

With

Set [Time1] AS '@.ParameterTime1'

...

Set [Time4] AS '@.ParameterTime4'

member [Measures].[Count1] as 'Sum ( { [Time1] } ,[Measures].[Count]) '

...

member [Measures].[Count4] as 'Sum ( { [Time4] } ,[Measures].[Count]) '

Select

{

[Measures].[Count1, ... , [Measures].[Count4]

} on Columns,

{

...

} on Rows

From [Cube]

It would be great if we still had dynamic queries supported with MDX which was available in SRS 2000. In that case I could build a query string and incorporate paramters in SET section. For example this type of query would not work in SRS 2005. I'm getting an error.

="With Set [Time1] AS ' " & Parameter!ParameterTime1 &"' ....."

If someone found any solution of using complex MDX queries with parameters, please respond. I am searching the web for a few days and no luck.

Thanks

Olga

Hi,

You can use parameters in the calculated members or sets, but you need to remove the character '.

With
Set [Time1] AS @.ParameterTime1
...
Set [Time4] AS @.ParameterTime4
member [Measures].[Count1] as 'Sum ( { [Time1] } ,[Measures].[Count]) '
...
member [Measures].[Count4] as 'Sum ( { [Time4] } ,[Measures].[Count]) '
Select
{
[Measures].[Count1, ... , [Measures].[Count4]
} on Columns,
{
...
} on Rows
From [Cube]

Regards,
Telmo Moreira|||

Telmo,

Thanks a lot ! You saved my day.

The query with parameters works fine.

Olga

|||

Hi,

I have a similar requirement but the number of sets i need to create is not fixed and needs to be dynamic. I will know the number of date ranges i need to filter on only at run time and i dont want to build an MDX query at runtime. Is there a simpler way of achieveing this by passing all the date ranges I require as a single parameter?

Thanks in Advance,

Arun

sql

Dynamic MDX Query

I am working on SRS 2005 report and need to calculate measures based on parameters. The new great feature of SRS2005 which allows to use parameters in MDX query unfortunately does not work in inner query. For example I am building 4 time sets based on specified date ranges and then calculate summary for each time set. So query looks like this:

With
Set [Time1] AS '@.ParameterTime1'
...
Set [Time4] AS '@.ParameterTime4'
member [Measures].[Count1] as 'Sum ( { [Time1] } ,[Measures].[Count]) '
...
member [Measures].[Count4] as 'Sum ( { [Time4] } ,[Measures].[Count]) '
Select
{
[Measures].[Count1, ... , [Measures].[Count4]
} on Columns,
{
...
} on Rows
From [Cube]

It would be great if we still had dynamic queries supported with MDX which was available in SRS 2000. In that case I could build a query string and incorporate paramters in SET section. For example this type of query would not work in SRS 2005. I'm getting an error.

="With Set [Time1] AS ' " & Parameter!ParameterTime1 &"' ....."

If someone found any solution of using complex MDX queries with parameters, please respond. I am searching the web for a few days and no luck.

Thanks

Olga

Hi,

You can use parameters in the calculated members or sets, but you need to remove the character '.

With
Set [Time1] AS @.ParameterTime1
...
Set [Time4] AS @.ParameterTime4
member [Measures].[Count1] as 'Sum ( { [Time1] } ,[Measures].[Count]) '
...
member [Measures].[Count4] as 'Sum ( { [Time4] } ,[Measures].[Count]) '
Select
{
[Measures].[Count1, ... , [Measures].[Count4]
} on Columns,
{
...
} on Rows
From [Cube]

Regards,
Telmo Moreira

|||

Telmo,

Thanks a lot ! You saved my day.

The query with parameters works fine.

Olga

|||

Hi,

I have a similar requirement but the number of sets i need to create is not fixed and needs to be dynamic. I will know the number of date ranges i need to filter on only at run time and i dont want to build an MDX query at runtime. Is there a simpler way of achieveing this by passing all the date ranges I require as a single parameter?

Thanks in Advance,

Arun

|||Hi,
is it possible to use a parameter as mentioned below?

select [Measures].[Internet Sales Amount] on 0,
@.ProductCategories on 1
from [Adventure Works]
And the MDX it would actually run against Analysis Services would be:
select [Measures].[Internet Sales Amount] on 0,
{[Product].[Category].&[1],[Product].[Category].&[2]} on 1
from [Adventure Works]

Monday, March 19, 2012

Dynamic Index Drop and Create

I am working on a data warehouse that is SQL Server 2000 based and what
I need to do is create two stored procs that do the following psuedo
code. I can write it myself but if someone has already written it then
why write it again or if you know of solutions that are close to what I
want that would be a good start. The reason that these need to be in
two seperate procs is that I want to seperate out the Drop and Creates
from the stored procedure that is loading the table. Instead of
hardcoding the drops and creates I want this procedure to be more
dynamic so that as we add indexes for tunning we don't have to maintain
our stored procedures.
proc_DropIndexes @.DatabaseName, @.TableName
- Write all necessary current index information to a work table for
@.DatabaseName and @.TableName to allow for recreation
- Drop all current indexes for @.DatabaseName and @.TableName
proc_CreateIndexes @.DatabaseName, @.TableName
- Read all necessary current index information from a work table for
@.DatabaseName and @.TableName to allow for recreation
- Create all indexes for @.DatabaseName and @.TableName
Thanks,
SpencerThe following appear to be good starts...
http://www.code-magazine.com/articl...b9cc0d4526e1913

Dynamic Index Drop and Create

I am working on a data warehouse that is SQL Server 2000 based and what
I need to do is create two stored procs that do the following psuedo
code. I can write it myself but if someone has already written it then
why write it again or if you know of solutions that are close to what I
want that would be a good start. The reason that these need to be in
two seperate procs is that I want to seperate out the Drop and Creates
from the stored procedure that is loading the table. Instead of
hardcoding the drops and creates I want this procedure to be more
dynamic so that as we add indexes for tunning we don't have to maintain
our stored procedures.
proc_DropIndexes @.DatabaseName, @.TableName
- Write all necessary current index information to a work table for
@.DatabaseName and @.TableName to allow for recreation
- Drop all current indexes for @.DatabaseName and @.TableName
proc_CreateIndexes @.DatabaseName, @.TableName
- Read all necessary current index information from a work table for
@.DatabaseName and @.TableName to allow for recreation
- Create all indexes for @.DatabaseName and @.TableName
Thanks,
SpencerThe following appear to be good starts...
http://www.code-magazine.com/articleprint.aspx?quickid=0301101&printmode=true
http://groups.google.com/group/microsoft.public.sqlserver.server/browse_thread/thread/1f4dd406fa18d676/8b9cc0d4526e1913?lnk=st&q=scripting+sql+server+indexes+create+drop&rnum=16&hl=en#8b9cc0d4526e1913

dynamic images in sql reporting services 2005

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

One way to do this is to include a hyperlink to the image. The URL of the hyperlink can be an expression controlled by the data in your report.|||

can we pass the URL using a parameter.

or can we do it like this.

i have a image file name in db(FirstName is the image name)

i have image path thru parameter

and in expression can i give like this

=Parameters!IPath.Value+Fields!FirstName.Value+".png"

it is working in the preview but not after deployment and in the runtime in IE

|||

RameshP wrote:

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

|||

We have similiar dashboard with traffic lights

I put an image in the field, and "value" field =

Code Snippet

=IIF(Fields!capacity_available.Value < 0.2, "icon_red-light.gif",

iif(Fields!capacity_available.Value < 0.4, "icon_yellow-light.gif",

iif(Fields!capacity_available.Value < 0.8, "icon_green-light.gif",

"icon_green-light.gif")))

dynamic images in sql reporting services 2005

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

One way to do this is to include a hyperlink to the image. The URL of the hyperlink can be an expression controlled by the data in your report.|||

can we pass the URL using a parameter.

or can we do it like this.

i have a image file name in db(FirstName is the image name)

i have image path thru parameter

and in expression can i give like this

=Parameters!IPath.Value+Fields!FirstName.Value+".png"

it is working in the preview but not after deployment and in the runtime in IE

|||

RameshP wrote:

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

|||

We have similiar dashboard with traffic lights

I put an image in the field, and "value" field =

Code Snippet

=IIF(Fields!capacity_available.Value < 0.2, "icon_red-light.gif",

iif(Fields!capacity_available.Value < 0.4, "icon_yellow-light.gif",

iif(Fields!capacity_available.Value < 0.8, "icon_green-light.gif",

"icon_green-light.gif")))

dynamic images in sql reporting services 2005

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

One way to do this is to include a hyperlink to the image. The URL of the hyperlink can be an expression controlled by the data in your report.|||

can we pass the URL using a parameter.

or can we do it like this.

i have a image file name in db(FirstName is the image name)

i have image path thru parameter

and in expression can i give like this

=Parameters!IPath.Value+Fields!FirstName.Value+".png"

it is working in the preview but not after deployment and in the runtime in IE

|||

RameshP wrote:

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

|||

We have similiar dashboard with traffic lights

I put an image in the field, and "value" field =

Code Snippet

=IIF(Fields!capacity_available.Value < 0.2, "icon_red-light.gif",

iif(Fields!capacity_available.Value < 0.4, "icon_yellow-light.gif",

iif(Fields!capacity_available.Value < 0.8, "icon_green-light.gif",

"icon_green-light.gif")))

dynamic images in sql reporting services 2005

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

One way to do this is to include a hyperlink to the image. The URL of the hyperlink can be an expression controlled by the data in your report.|||

can we pass the URL using a parameter.

or can we do it like this.

i have a image file name in db(FirstName is the image name)

i have image path thru parameter

and in expression can i give like this

=Parameters!IPath.Value+Fields!FirstName.Value+".png"

it is working in the preview but not after deployment and in the runtime in IE

|||

RameshP wrote:

Hi all,

I am currently working on some reports where I need to display images dynamically.

there is one total field whose value ranges between 0 and 100 %. amd I need to display different images depending on the range of the value.

for example,

if the range is between

80% - 100% smily face.

60% - 80% normal face

40% - 60% sad face.

Can any one help in approaching this.

Initially I worked with only static embeded images.

It also helps me in solving another problem.

I need to change the company logo (header image) as per the company in the common report template provided by the provider dynamically.

Thanks in advance.

waiting for an early help as it is very urgent for me.

Regards,

Ramesh P

|||

We have similiar dashboard with traffic lights

I put an image in the field, and "value" field =

Code Snippet

=IIF(Fields!capacity_available.Value < 0.2, "icon_red-light.gif",

iif(Fields!capacity_available.Value < 0.4, "icon_yellow-light.gif",

iif(Fields!capacity_available.Value < 0.8, "icon_green-light.gif",

"icon_green-light.gif")))

Dynamic Grouping with Report Designer

I've got this working -- I allow users to have 2 groups, and choose what they want to group by. I'd like to add one extra bit of functionality -- for the inner grouping, I would like my users to have the option "None" -- i.e. don't have an inner group.

I've tried setting the group expression of the second (inner) group to "" when the user chooses the "None" option but the report errors out. Any suggestions as to how to dynamically get rid of the inner group?

Thx

Helen

Helen:

I had a similar requirement and here's how I solved it. For the "None" entry at each grouping level you'll need to include a value for it in the combobox that's the following functions will recognize. Include the following in the "Code" and call the appropriate function. You're probably most interested in the "GetSubGrouping" function but I'm including "GetGrouping" so you can also use it at the main grouping level. Include the call to GetSubGrouping in the "Group on"; you'll also find that "GetField" is useful instead of coding a lot of iif's for controlling the visibility of the groupings.

Hope this helps

Glenn L

SharedFunction GetGrouping(ByVal Parameters AsObject, ByVal Fields AsObject) AsObject

Return GetField(Fields, Parameters("GroupBy").Value, "no_grouping")

EndFunction

SharedFunction GetSubGrouping(ByVal Parameters AsObject, ByVal Fields AsObject) AsObject

Return IIf(Parameters("GroupBy").Value = "no_grouping" _

Or Parameters("GroupBy").Value = Parameters("SubGroupBy").Value, Nothing, GetField(Fields, Parameters("SubGroupBy").Value, "no_sub_grouping"))

EndFunction

SharedFunction GetField(ByVal Fields AsObject, ByVal FieldName AsString, ByVal NoGroupingValue AsString) AsObject

If Trim$(FieldName) = Trim$(NoGroupingValue) Then

ReturnNothing

ElseIf IsDate(Fields(Trim$(FieldName)).Value) Then

Return FormatDateTime(Fields(Trim$(FieldName)).Value, 2)

Else

Return Fields(Trim$(FieldName)).Value

EndIf

EndFunction

|||

Thank you Glenn! That did the trick!

Helen

Dynamic Grouping with Report Designer

I've got this working -- I allow users to have 2 groups, and choose what they want to group by. I'd like to add one extra bit of functionality -- for the inner grouping, I would like my users to have the option "None" -- i.e. don't have an inner group.

I've tried setting the group expression of the second (inner) group to "" when the user chooses the "None" option but the report errors out. Any suggestions as to how to dynamically get rid of the inner group?

Thx

Helen

Helen:

I had a similar requirement and here's how I solved it. For the "None" entry at each grouping level you'll need to include a value for it in the combobox that's the following functions will recognize. Include the following in the "Code" and call the appropriate function. You're probably most interested in the "GetSubGrouping" function but I'm including "GetGrouping" so you can also use it at the main grouping level. Include the call to GetSubGrouping in the "Group on"; you'll also find that "GetField" is useful instead of coding a lot of iif's for controlling the visibility of the groupings.

Hope this helps

Glenn L

SharedFunction GetGrouping(ByVal Parameters AsObject, ByVal Fields AsObject) AsObject

Return GetField(Fields, Parameters("GroupBy").Value, "no_grouping")

EndFunction

SharedFunction GetSubGrouping(ByVal Parameters AsObject, ByVal Fields AsObject) AsObject

Return IIf(Parameters("GroupBy").Value = "no_grouping" _

Or Parameters("GroupBy").Value = Parameters("SubGroupBy").Value, Nothing, GetField(Fields, Parameters("SubGroupBy").Value, "no_sub_grouping"))

EndFunction

SharedFunction GetField(ByVal Fields AsObject, ByVal FieldName AsString, ByVal NoGroupingValue AsString) AsObject

If Trim$(FieldName) = Trim$(NoGroupingValue) Then

ReturnNothing

ElseIf IsDate(Fields(Trim$(FieldName)).Value) Then

Return FormatDateTime(Fields(Trim$(FieldName)).Value, 2)

Else

Return Fields(Trim$(FieldName)).Value

EndIf

EndFunction

|||

Thank you Glenn! That did the trick!

Helen

Sunday, March 11, 2012

Dynamic formulas driven by table

I'm working with a DB design that seems to me to be rather complex.

This is a very slimmed down version of what I'm doing, but I believe it
is enough to get my question resolved.

Here is my layout.

These 4 tables are used to generate a questionaire.

Survey OrderID
========= ==========
SurveyID OrderID
OrderID QuestionGrpID

QGrp Questions
============= =============
QuestionGrpID QuestionID
QuestionID QuestionText

The following two tables are used to calculate a report that is sent to
the customer.

RawData
=========================
OrderID
QuestionID
Value is string but is Cast as decimal for numeric formulas

Metrics
==============================================
QuestionGroupID | ReportText | Formula | MetID
==============================================
2 | % Support Staff of Total | OP21/(OP21+OP22+OP23) | 1

The OP references are questionIDs

Now to calculate the result for the report we programatically parse the
formula creating a temp table (table name = Temp & orderID & _ &
QuestionID) with OrderID and OPxx as the field names. We create one
table for each question.

We then use dynamic SQL again to calculate the result using the above
formula

SELECT OP21/(OP21+OP22+OP23) FROM Temp5_21, Temp5_22, Temp5_23 WHERE
Temp5_21.OrderID = Temp5_22.orderID AND Temp5_22.OrderID =
Temp5_23.OrderID

This select is used to create a single table of calculated values.
This table is in turn used to tell the customer how they compare to
other customers. Percentile, Mean, Median, Std Dev, and a few others. I
don't claim this part of the project, but I'm not sure how I might have
done it, had it been assigned to me.

MY PROBLEM!!!
Sometimes a 0 is valid data and is the denominator of a devision
calculation. Since this is so dynamic and it might be difficult to
determine when division is used. I need a way to default divide by 0
execptions to NULL. This DB is on a hosted server.
Thanks for bearing with me,

Greg Kelley"yzarc" <yzarcman@.gmail.com> wrote in message
news:1105629819.876049.179950@.c13g2000cwb.googlegr oups.com...
> I'm working with a DB design that seems to me to be rather complex.
> This is a very slimmed down version of what I'm doing, but I believe it
> is enough to get my question resolved.
> Here is my layout.
> These 4 tables are used to generate a questionaire.
> Survey OrderID
> ========= ==========
> SurveyID OrderID
> OrderID QuestionGrpID
> QGrp Questions
> ============= =============
> QuestionGrpID QuestionID
> QuestionID QuestionText
>
> The following two tables are used to calculate a report that is sent to
> the customer.
> RawData
> =========================
> OrderID
> QuestionID
> Value is string but is Cast as decimal for numeric formulas
>
> Metrics
> ==============================================
> QuestionGroupID | ReportText | Formula | MetID
> ==============================================
> 2 | % Support Staff of Total | OP21/(OP21+OP22+OP23) | 1
> The OP references are questionIDs
> Now to calculate the result for the report we programatically parse the
> formula creating a temp table (table name = Temp & orderID & _ &
> QuestionID) with OrderID and OPxx as the field names. We create one
> table for each question.
> We then use dynamic SQL again to calculate the result using the above
> formula
> SELECT OP21/(OP21+OP22+OP23) FROM Temp5_21, Temp5_22, Temp5_23 WHERE
> Temp5_21.OrderID = Temp5_22.orderID AND Temp5_22.OrderID =
> Temp5_23.OrderID
> This select is used to create a single table of calculated values.
> This table is in turn used to tell the customer how they compare to
> other customers. Percentile, Mean, Median, Std Dev, and a few others. I
> don't claim this part of the project, but I'm not sure how I might have
> done it, had it been assigned to me.
> MY PROBLEM!!!
> Sometimes a 0 is valid data and is the denominator of a devision
> calculation. Since this is so dynamic and it might be difficult to
> determine when division is used. I need a way to default divide by 0
> execptions to NULL. This DB is on a hosted server.
> Thanks for bearing with me,
> Greg Kelley

Check out SET ANSI_WARNINGS, SET ARITHABORT and "Behavior if Both ARITHABORT
and ARITHIGNORE Are Set ON" in Books Online - this will do what you want.
But, it's not a recommended solution, because it means you can't use
features like distributed queries and indexed views, and it may create
problems with other code.

Alternatively, you might be able to store your formulae with a NULLIF around
the divisor:

OP21/NULLIF((OP21+OP22+OP23), 0)

If that's not possible, and you can't be sure what the divisor will be, then
you would probably have to look at solving it outside the database, either
by parsing the formulae to insert a NULLIF dynamically, or perhaps by doing
some calculations externally.

Simon|||Thanks,
I appreciate the reply. I'm using a fairly basic parser to divide the
OP codes out and creat the table. I may look at tagging the OP codes so
that I can strip anything out that is not an OP code for creating my
tables.

Thanks again,
Greg