Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Tuesday, March 27, 2012

Dropping an auto numbered primary key and add a new one

The table I am using have a column called Key which is the primary key of the table and a auto number. This primary key is not a foreign key in any other table.

I need to write SQL to drop the current primary key and add a new one Say "RecordId"

as the new primary key and which should be a autonumber too.

any idea.

thanks in advance

droping and adding a primary key on a column wont affest its 'identity' property, so simply drop the primary key and add again with the new name u want...

alter table tablename drop constraint oldpk

alter table tablename add constraint newpk primary key(id)

|||

What's the point? It is easy enough, just drop the column and add another one, but there might be an easier way to do what you are wanting to do.

Here is a script that does it:

set nocount on
drop table test
go
create table test
(
testId int identity constraint PKtest primary key,
value datetime default (getdate())
)
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
insert into test default values
go
select *
from test
go
alter table test
drop PKtest
go
alter table test
drop column testId
go
select *
from test
go
alter table test
add testId int identity (2,2) constraint PKtest primary key
go
select *
from test --the identity values will start at 2 and go up by steps of 2 (so you can see the diff)

sql

Wednesday, March 21, 2012

Drop tables where name matches a pattern

I have an arbitrary number of tables in a SQL2000 db with names matching
'MyTable_%'.
Is there a simple way of dropping these with a SQL command?
LMcPheeThere is an undocumented and unsupported way:
EXEC sp_msForEachTable 'IF ''?'' LIKE ''MyTable[_]%'' DROP TABLE ?;';
You should probably test this in a restored backup before you do it to your
production database (though this sounds like a very peculiar thing to do to
a production database, anyway).
As I mentioned yesterday, this will only work if none of these tables have
foreign keys referencing them OR if the cursor in sp_msforeachtable just
happens to process the tables in dependency order.
A safer way is to probably generate the script and execute it manually, this
will allow you to inspect the script and make any necessary changes first.
Using Results in Text in Query Analyzer, run:
SET NOCOUNT ON;
SELECT 'DROP TABLE '+TABLE_NAME +';'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'MyTable[_]%';
Now you can copy the output, paste it to the top pane or a new query editor
window, and run it.
A
"lmcphee" <lmcphee@.discussions.microsoft.com> wrote in message
news:63D0D021-F83D-4DF1-ABD7-EBD2F3EC3074@.microsoft.com...
>I have an arbitrary number of tables in a SQL2000 db with names matching
> 'MyTable_%'.
> Is there a simple way of dropping these with a SQL command?
> LMcPhee|||Try,
-- non documented sp
exec sp_msforeachtable 'if parsename(''?'', 1) like ''my_table%'' drop table
?'
go
-- using a select statement to copy, paste and execute the result
select 'drop table [' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']' + char(13)
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME like 'MyTable_%'
go
-- using a cursor and dynamic sql
declare @.sql nvarchar(4000)
declare my_cursor cursor
local
fast_forward
for
select 'drop table [' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']' as sql
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME like 'MyTable_%'
open my_cursor
while 1 = 1
begin
fetch next from my_cursor into @.sql
if @.@.error != 0 or @.@.fetch_status != 0 break
exec sp_executesql @.sql
end
close my_cursor
deallocate my_cursor
go
AMB
"lmcphee" wrote:

> I have an arbitrary number of tables in a SQL2000 db with names matching
> 'MyTable_%'.
> Is there a simple way of dropping these with a SQL command?
> LMcPhee

Monday, March 19, 2012

Drop List problem

Hi,

When I'm creating a dropdown list prompt from a field which has large number of distinct values (OrgUnit codes etc.) I get an empty list.

Can anyone advice on this issue ?

Is your drop down list bound to a dataset.

Thanks,

vnswathi.

|||

Hi,

We are using Cognos right now and moving to SSRS. In Cognos we don't have this problem and this problem occur in SSRS with all kind of field types if it has large amount of distinct values. Maybe it's a restriction in SSRS ? and if so, maybe you know the upper limit ?

Thanks,

Yuval

|||

hi

i dont think there would be any problem with the fields size

u need to create a separate dataset for the drop down list prompt.

and then choose the from query parameter...

hope it solves your issue.

regards,

www.snktheone.com

Friday, March 9, 2012

Drop automatically-created indexes

Hi
We have a SQL Server 2000 database. On three of the tables (used by an
ERP-system) there are a huge number of automatically-created indexes (we are
hitting the maximum limit). These indexes slow down inserts and updates, and
prevent us from create other (more meaningful) indexes. We have tried to drop
these indexes, but we can’t.
Is there a way to drop/delete automatically-created indexes, or to turn this
functionality off?
Or to you have other suggestions?
Here is some more information about automatically-created indexes:
http://www.microsoft.com/sql/techinf...utoindexes.asp
--JeyLey
Jey
There are called Statistics. SQL Server creates statistics on columns in
order to
retrieve the data in more efficient way. This article makes it clear how
does it work.You can run sp_updatestatistics system stored procedure to
update automatically reated statistics.For more details please refer to BOL.
eyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we
are
> hitting the maximum limit). These indexes slow down inserts and updates,
and
> prevent us from create other (more meaningful) indexes. We have tried to
drop
> these indexes, but we cant.
> Is there a way to drop/delete automatically-created indexes, or to turn
this
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techinf...utoindexes.asp
> --JeyLey
|||In addition to Uri's post:
You can drop these auto-created statistics using the DROP STATISTICS command. But note that
auto-created statistics can benefit performance.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JeyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we are
> hitting the maximum limit). These indexes slow down inserts and updates, and
> prevent us from create other (more meaningful) indexes. We have tried to drop
> these indexes, but we can't.
> Is there a way to drop/delete automatically-created indexes, or to turn this
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techinf...utoindexes.asp
> --JeyLey

Drop automatically-created indexes

Hi
We have a SQL Server 2000 database. On three of the tables (used by an
ERP-system) there are a huge number of automatically-created indexes (we are
hitting the maximum limit). These indexes slow down inserts and updates, and
prevent us from create other (more meaningful) indexes. We have tried to dro
p
these indexes, but we can’t.
Is there a way to drop/delete automatically-created indexes, or to turn this
functionality off?
Or to you have other suggestions?
Here is some more information about automatically-created indexes:
http://www.microsoft.com/sql/techin...autoindexes.asp
--JeyLeyJey
There are called Statistics. SQL Server creates statistics on columns in
order to
retrieve the data in more efficient way. This article makes it clear how
does it work.You can run sp_updatestatistics system stored procedure to
update automatically reated statistics.For more details please refer to BOL.
eyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we
are
> hitting the maximum limit). These indexes slow down inserts and updates,
and
> prevent us from create other (more meaningful) indexes. We have tried to
drop
> these indexes, but we cant.
> Is there a way to drop/delete automatically-created indexes, or to turn
this
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techin...autoindexes.asp
> --JeyLey|||In addition to Uri's post:
You can drop these auto-created statistics using the DROP STATISTICS command
. But note that
auto-created statistics can benefit performance.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JeyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we a
re
> hitting the maximum limit). These indexes slow down inserts and updates, a
nd
> prevent us from create other (more meaningful) indexes. We have tried to d
rop
> these indexes, but we can't.
> Is there a way to drop/delete automatically-created indexes, or to turn th
is
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techin...autoindexes.asp
> --JeyLey

Drop automatically-created indexes

Hi
We have a SQL Server 2000 database. On three of the tables (used by an
ERP-system) there are a huge number of automatically-created indexes (we are
hitting the maximum limit). These indexes slow down inserts and updates, and
prevent us from create other (more meaningful) indexes. We have tried to drop
these indexes, but we canâ't.
Is there a way to drop/delete automatically-created indexes, or to turn this
functionality off?
Or to you have other suggestions?
Here is some more information about automatically-created indexes:
http://www.microsoft.com/sql/techinfo/tips/administration/autoindexes.asp
--JeyLeyJey
There are called Statistics. SQL Server creates statistics on columns in
order to
retrieve the data in more efficient way. This article makes it clear how
does it work.You can run sp_updatestatistics system stored procedure to
update automatically reated statistics.For more details please refer to BOL.
eyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we
are
> hitting the maximum limit). These indexes slow down inserts and updates,
and
> prevent us from create other (more meaningful) indexes. We have tried to
drop
> these indexes, but we can?t.
> Is there a way to drop/delete automatically-created indexes, or to turn
this
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techinfo/tips/administration/autoindexes.asp
> --JeyLey|||In addition to Uri's post:
You can drop these auto-created statistics using the DROP STATISTICS command. But note that
auto-created statistics can benefit performance.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JeyLey" <JeyLey@.nospam.nospam> wrote in message
news:D288B8DC-2E00-4E68-ADAC-7DBD3DF16837@.microsoft.com...
> Hi
> We have a SQL Server 2000 database. On three of the tables (used by an
> ERP-system) there are a huge number of automatically-created indexes (we are
> hitting the maximum limit). These indexes slow down inserts and updates, and
> prevent us from create other (more meaningful) indexes. We have tried to drop
> these indexes, but we can't.
> Is there a way to drop/delete automatically-created indexes, or to turn this
> functionality off?
> Or to you have other suggestions?
> Here is some more information about automatically-created indexes:
> http://www.microsoft.com/sql/techinfo/tips/administration/autoindexes.asp
> --JeyLey

Sunday, February 26, 2012

drop ##temp

due to unavoidable reasons i had to use a ## temp table in a SP,

ie i had to dynamically create a table whose (number of)columns i come to know at runtime..

if i do thi ::set @.sql = 'create #table....select some columns _ append varchar(10)'

then insert into #temp....temp is not valid here..so i used ##temp

now i need to explicitly drop it...also in catch block , i need to make a provision for droping it incase of an error in runnin proc...some kind os IF EXISTS drop ##temp.... as i dont know if it'll be created by that time or not..how do i do it..there is ofcource no entry in sysobjects....where is the entry for temp tables...tempdb dosent have system tables..!!

Can you provide SQl of SP...

~Mandip

|||

Nitin:

Since in this case it is a global temp table -- that is, it starts with ##, it will explicitly appear in sysobjects in tempdb:

create table dbo.##temp
( what varchar (5)
)

select uid, id, left (name, 20) as name from tempdb.dbo.sysobjects where name = '##temp'

if exists
( select 0 from tempdb.dbo.sysobjects
where name = '##temp'
and type = 'U'
)
begin
print 'Dropping the table.'
print ' '
drop table ##temp
end

select id, left (name, 20) as name from tempdb.dbo.sysobjects where name = '##temp'


-- -
-- O U T P U T :
-- -

-- uid id name
-- -- --
-- 1 853242293 ##temp
--
-- (1 row(s) affected)

-- Dropping the table.
--
-- id name
-- -- --

-- (0 row(s) affected)

Dave

|||

Thanks Dave.....

actually i was tryin this...

select * from sysobjects where name like '##temp'

hence the question.....now as u told it wors fine while i do this :: select * from tempdb.dbo.sysobjects where name like '##temp'

tell me if 2 ppl r running this sp simultaneously , will 1 of them get an error (##temp already exist..) or he'll have to wait for a tempdb lock.. ?

|||

Nitin:

Yes, because you are using a GLOBAL temp table this is a potential problem. However, since you are in a stored procedure, the procedure will automatically drop the temp table when it goes out of context should you use a non-global temp table -- one that starts with # instead of ##. I don't see why this would not be acceptable. Are you doing something in which you potentially need the temp table to have persistence beyond the scope of the procedure?


Dave

|||

dave :

i am creating my temp table by creating a sql string for it and then executing it..as num of columns is decided on the runtime..below is the query..

declare @.mytable varchar(500)

set @.mytable = 'CREATE TABLE ##temp (UserId int,'

select @.mytable = @.mytable + 'Plan_' + cast(PlanCode AS nvarchar(10)) + ' varchar(5),'

FROM (SELECT distinct PaymentPlanPlanTypeCode FROM #sometable) p

SET @.mytable = LEFT(@.mytable, LEN(@.mytable) - 1)

SET @.mytable = @.mytable + ')'

print @.mytable

exec (@.mytable)

i need this temp table in this 1 SP only but when i replace the ##temp with , #temp , the table is not getting created... i dont know why..probably some scope problem... also i ran out of the option of using table datatype as my proc further refers this table and i cant declare it inside a string..

see this as well :

--1

declare @.sql varchar(100)

set @.sql='create table ##tem (a int)'

exec (@.sql)

select * from #tem

error : invalid object #tem

--2

create table #tem (a int)

select * from #tem

gives the result.

|||

Nitin:

You are right, you do have a scope problem. I have a rather"dirty" idea, but I will have to test it out and unfortunately I won't have any time for at least an hour or so. Hopefully, you can get a better idea from somebody else can get you a better idea than what I have. I will check back in a while and if nobody else has come up with something I will test out my "dirty trick."

Dave

|||

Nitin:

One more question: I am assuming that this is not a "performance critical" procedure and that even though it is possible for multiple users to execute this procedure at the same time it is not likely. Is that assumption correct or is it rather likely that multiple users will execute your procedure concurrently?

Dave

|||

hi ,

this proc is for some mis report...though data will be large, its unlikely that more then a few users will use it... but agn..can be more then 1 at a time...

so i guess ur assumption can hold..

|||

Nitin:

This is my "dirty" suggestion. I tried it out and it seems to work. If you get another idea it will probably be better. Good luck.

Dave

-- --
-- First, I think I might have used the TABLOCK optimizer hint less than a handful
-- of times over my entire carreer. I don't think I've ever used TABLOCKX other
-- than in demo code. So to begin with I am iffy on the code that follows.
--
-- With that said, understand that what this code tries to use the execute string.
-- to build the format of the target table into a global temp table. Once that is
-- done a SELECT INTO is used to grab that format and use it to create the
-- intended local temp table. Once that is done the global temp table can be
-- dropped. This TABLOCKX optimizer hint means that this portion of the code
-- is single-threaded and is definite bottleneck. If this is not an intensely
-- used query this might be sufficient.
--
-- Unfortunately, there are additional bottlenecking problems. As I suspected,
-- The "select into" portion of the query puts exclusive locks on keys (1)
-- SYSOBJECTS, (2) SYSINDEXES and (3) SYSCOLUMNS of the tempdb database. Also,
-- exclusive intent locks are put on all three of these tables plus
-- (1) SYSCOMMENTS, (2) SYSDEPENDS, and (3) SYSPERMISSIONS and (4) SYSPROPERTIES.
--
-- If you wish to test this out, just comment out the COMMIT TRAN command,
-- run the procedure and then run SP_LOCK. To release the locks exeucte the
-- COMMIT TRAN statement.
--
-- Therefore, it is critical that if this kind of code is used in production that
-- the construction of the TEMP table take place OUTSIDE of the actual processing
-- transaction so that the code below executes in as few microseconds as possible
-- and reduces the profile of the bottleneck.
--
-- I also tested this with no transaction enclosures and exeucted the WAITFOR so
-- that I could see how it locked outside of any transaction enclosures. I
-- commented out my BEGIN TRAN and END TRAN satements, ran with the WAITFOR in
-- affect and did an SP_LOCK with an outside connection. No locks were retained.
-- What to understand with all of this is that (1) the TABLOCKX hint will single
-- thread this and that is not particular good; however, (2) SQL Server issues
-- locks that might otherwise single-thread you briefly anyway; so this might not
-- be TOO bad. (3) Always be careful how you use SELECT INTO syntax; it can
-- also bite you.
--
-- I really don't like this code; but if you don't get any other suggestion, it
-- might be worth a try.
--
-- Dave
--
-- --
--begin tran doWhat

exec ( 'create table ##what (what varchar (20) ) ' )

select * into #what from ##what (TABLOCKX) where 1=0

if exists
( select 0 from tempdb.dbo.sysobjects
where type = 'U'
and name = '##what'
)
drop table ##what

select * from #what

--waitfor delay '0:01:00.000'

drop table #what

--commit tran

go

-- -
--
-- -

-- spid dbid ObjId IndId Type Resource Mode Status
-- -- - - --
-- 55 2 6 0 TAB IX GRANT
-- 55 2 1 0 TAB IX GRANT
-- 55 2 2 0 TAB IX GRANT
-- 55 2 12 0 TAB IX GRANT
-- 55 2 9 0 TAB IX GRANT
-- 55 2 11 0 TAB IX GRANT
-- 55 2 1529959413 0 TAB Sch-M GRANT
-- 55 2 3 2 KEY (9401125ee398) X GRANT
-- 55 2 1 3 KEY (f50024d97b7f) X GRANT
-- 55 2 1 2 KEY (fc00a92d9bd9) X GRANT
-- 55 2 2 1 KEY (bc009dbece03) X GRANT
-- 55 2 1 1 KEY (bc004820585b) X GRANT
-- 55 2 3 1 KEY (bd00770e8a50) X GRANT
-- 55 2 1513959356 0 TAB Sch-M GRANT
-- 55 2 2 1 KEY (f500783daf5c) X GRANT
-- 55 2 3 1 KEY (f60025843207) X GRANT
-- 55 2 1 3 KEY (bc003d203e1f) X GRANT
-- 55 2 1 1 KEY (f50051d91d3b) X GRANT
-- 55 2 1 2 KEY (9b16f50455d2) X GRANT
-- 55 2 3 2 KEY (cd019d01c693) X GRANT
-- 55 33 0 0 DB S GRANT
-- 55 2 3 0 TAB IX GRANT

|||

thanks a lot for ur time dave....im tempted to use this..i'll do some testing and go for it... ya i cant run away from select into...infact that was the thing i was trying earlier while generating the query string...so im kinda ready for that...

cheers

nitin

|||

You can do below:

create table #tbl( /* put fixed columns here. those that are not decided dynamically )

-- use ALTER TABLE to add the columns dynamically

exec('alter table "#tbl" add c1 int, c2 int...')

select ...

Note, however that this has performance implications due to the excessive amount of recompilations triggered due to the schema changes. In above case, pretty much every line will trigger recompile of the entire SP (SQL2000) or statement (SQL2005).

Drives Information

Can any body tell me that Can I know the number of drives in system as well
as the used and free spaces of that harddrive through xp_cmdshell
Thanks
Noor
Hi,
Execute the below command from query analyzer:-
master..xp_fixeddrives
The above command will give you all the local drives and free space in MB.
Thanks
Hari
MCDBA
"Noor" <noor@.ngsol.com> wrote in message
news:OEpjKVnWEHA.3492@.TK2MSFTNGP10.phx.gbl...
> Can any body tell me that Can I know the number of drives in system as
well
> as the used and free spaces of that harddrive through xp_cmdshell
> Thanks
> Noor
>
|||Thanks Hari, but it gave the primary drive letter and it's space. I want the
all available drives and it's spaces.
Thanks
Noor
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:uCgFFknWEHA.3716@.TK2MSFTNGP11.phx.gbl...
> Hi,
> Execute the below command from query analyzer:-
> master..xp_fixeddrives
>
> The above command will give you all the local drives and free space in MB.
> --
> Thanks
> Hari
> MCDBA
> "Noor" <noor@.ngsol.com> wrote in message
> news:OEpjKVnWEHA.3492@.TK2MSFTNGP10.phx.gbl...
> well
>
|||Hi Noor,
master..xp_fixeddrives will give the information for all fixed drives in the
machine.
The network drives will not be listed. For that you can use xp_cmdshell 'dir
driveletter'
Thanks
Hari
MCDBA
"Noor" <noor@.ngsol.com> wrote in message
news:#Q4u3RoWEHA.2844@.TK2MSFTNGP09.phx.gbl...
> Thanks Hari, but it gave the primary drive letter and it's space. I want
the[vbcol=seagreen]
> all available drives and it's spaces.
> Thanks
> Noor
> "Hari" <hari_prasad_k@.hotmail.com> wrote in message
> news:uCgFFknWEHA.3716@.TK2MSFTNGP11.phx.gbl...
MB.
>

Friday, February 24, 2012

Drillthrough Security Conundrum AS 2005

Hi,

I'm looking for some inspiration on how to solve the following issue.

I'm working on a cube that contains crime data. I have a number of reports built using SSRS that show summary totals for different types of crime. In addition, there are a number of linked reports where the user can drill through to the underlying details of the crimes in the fact table fact table. These reports use the DRILLTHROUGH statement via the OLE DB provider for OLAP. So far, so good.

The client now wants to restrict drillthrough on certain types of crime.

Essentially, if a user is a member of Role1, they should be able to see the summary total for Crime A in the main report but they should NOT be able to drillthrough to the details of that summary

If the user is a member of Role2, they should be able to drill through to the detail level.

So far, I cannot see a way to do this with role permissions. My understanding and experience of the role based security thus far is as follows (please correct me if I'm wrong)

1) You can enable or disable drill through at the cube level for a particular role via the Cubes > Drillthrough Access property. This is too restrictive for my needs in this case

2) You can hide certain dimension members via Dimension Data tab but this results in the particular crime types not being displayed in the main report (i.e. you can't see the summary total for that crime)

3) You can restrict access to certain cell values via Cell Data but again this results in a value like N/A being displayed in the main report.

Has anyone faced a similar problem and come up with a way to do this?

Any feedback appreciated

NJDUNNE

The right way to approach this is through dimension security (Dimension Data tab). Drillthrough respects all the dimension security settings. You can restrict access to details, but make sure that Visual Totals=false, therefore you will see the summaries but won't be able to go to details.|||

Hi ,

Do u know if we can create drill through reports in SSRS through SSAS & Sql Server 2005 as the Database . I want to know how this can be done ?

Regards

Rashmi

Drillthrough Security Conundrum AS 2005

Hi,

I'm looking for some inspiration on how to solve the following issue.

I'm working on a cube that contains crime data. I have a number of reports built using SSRS that show summary totals for different types of crime. In addition, there are a number of linked reports where the user can drill through to the underlying details of the crimes in the fact table fact table. These reports use the DRILLTHROUGH statement via the OLE DB provider for OLAP. So far, so good.

The client now wants to restrict drillthrough on certain types of crime.

Essentially, if a user is a member of Role1, they should be able to see the summary total for Crime A in the main report but they should NOT be able to drillthrough to the details of that summary

If the user is a member of Role2, they should be able to drill through to the detail level.

So far, I cannot see a way to do this with role permissions. My understanding and experience of the role based security thus far is as follows (please correct me if I'm wrong)

1) You can enable or disable drill through at the cube level for a particular role via the Cubes > Drillthrough Access property. This is too restrictive for my needs in this case

2) You can hide certain dimension members via Dimension Data tab but this results in the particular crime types not being displayed in the main report (i.e. you can't see the summary total for that crime)

3) You can restrict access to certain cell values via Cell Data but again this results in a value like N/A being displayed in the main report.

Has anyone faced a similar problem and come up with a way to do this?

Any feedback appreciated

NJDUNNE

The right way to approach this is through dimension security (Dimension Data tab). Drillthrough respects all the dimension security settings. You can restrict access to details, but make sure that Visual Totals=false, therefore you will see the summaries but won't be able to go to details.|||

Hi ,

Do u know if we can create drill through reports in SSRS through SSAS & Sql Server 2005 as the Database . I want to know how this can be done ?

Regards

Rashmi

Sunday, February 19, 2012

Drillthrough is incomplete

I have a strange problem in my cube when drilling down to details.

If I run the following query and leave out the DRILLTHROUGH, I get only one number as result, 7.

The Measure Counter is defined as "COUNT on lines" of the source table. So I expect that the number 7 results from 7 lines in the source table - And when I run an SQL query translated to use the same filter options as WHERE part, I do indeed get 7 lines matching the date and other settings I asked for. Everything ok so far.

When I execute the MDX query with DRILLTHROUGH I get only 3 lines as result - I remove the DRILLTHROUGH again and get 7 as result again... what can be the reason for this?

DRILLTHROUGH SELECT {[Measures].[Counter]} ON 0 FROM [Cube] WHERE ([Final Level].[Level Hierarchy].&[-6], [Action].[Action].&[4], [Submitted Date].[Submitted Date].[Submitted Year].&[2007], [LMU-SL].[LMU-SL Hierarchy].&[3])

Perhaps there are duplicate records at the measure group granularity, therefore in the cube you ended up with only 3 distinct records, but the total value is still correct - 7.|||

Mosha Pasumansky wrote:

Perhaps there are duplicate records at the measure group granularity, therefore in the cube you ended up with only 3 distinct records, but the total value is still correct - 7.

Mosha, thanks for answering.

I understand what you mean, but I can confirm that this is not the reason / solution.

I did confirm that in fact the 7 rows are distinct for the granularity of the measure group. They each have their own primary key in the database, and the measure group is based on this table, on this pk.

I browse the cube in Excel, and there are more combinations like this one where a number of lines is counted in cube ("11" in this other case), 11 distinct lines can be confirmed using sql, but no line at all is returned for drill. If I create my MDX without drillthrough, I get "11" as value for the measure. If I put "drillthrough" before it - I get no results at all.

As always, it is all far more complicated, as you guessed... My original MDX showed 4 dimensions sliced. 3 of them are really dimension on the measure group, these dimensions are joined in as regular to the measure group. The 4th one is a dimension on a measure group with a finer grain, a deeper level of detail as I try to imagine it. This 4th dimension is joined to the finer grain as a regular dimension, and to the measure group queried using m-n joining "back up from finer detail level".

For information, I can display a row count on the detail measure group as well, and these numbers in the cube are also perfectly in line with tests done using sql. But drills to the detail group give no results at all (even if the cube showed some 10 (distinct) detail lines for this dimension, verified using sql.

I suspect the problem is around that m-n from a finer level, since drilling into both measure groups without using this dimensions mix from different grains works perfectly fine. I am quite sure my dimension - measure setup is correct, since all counts in the cube come out the same value as manual sql test comparisons.

I am really a bit worried here with the reliability of SSAS 2005.

I am now cleaning out the db to only host the 7 lines in question as all data available, opposed to 2.5 mill on the queried level and 10 mill lines in the finer grain section to see if that makes any change in the result, and reload the whole SSAS db with this greatly simplified amount of data. I might also use CTP of SP2 to see what happens.

|||

Ralf_from_Europe wrote:

I am now cleaning out the db to only host the 7 lines in question as all data available, opposed to 2.5 mill on the queried level and 10 mill lines in the finer grain section to see if that makes any change in the result, and reload the whole SSAS db with this greatly simplified amount of data.

I think I found out the worst I could imagine: With less data loaded, or better: only data that falls within the area I slice for, I get ALL my 7 lines as result in drill and as cube measure. I did not change any settings in the project or made any changes to the query. I only threw out around 12 mill lines of data from the source db... I really doubt the precision, or maybe better the reliability of SSAS now.

In case anyone wants to know I noticed the difference between the lines given back and not given back: I suspect the problem I have is somewhere along the aggregations build for the cube. Why? The lines that work are in one category of a dimension (a pretty simple one with the order state, 8 items, like in "ordered", "mailed", "received" or "returned" and so). Anyway, the lines that work are in one state, the ones that do not are in another state.

This dimension is NOT used in this example, and also not part of my MDX query, neither with or without the drillthrough part. I suspect there is no aggregation on this dimension since the design wizard did not call an 8 entry dimension worth it. Then again, I did not change the aggregation setup, I only cleaned the source db of other data...

I am SERIOUSLY in doubt now! Trying SP2 CTP now...

drill-through from matrix subtotals

I have a matrix report (Report1) with rowgroup and columngroup. Both
contain also totals (defined as group subtotals). The number of rows and
columns varies.
Area1 Area2 Totals
Product 1 10 12 22
Product 2 7 11 18
Totals 17 23 40
I also have another report where I can list this data more detailed
(Report2). Report2 uses Product and Area as parameters where possible
values are 'Product 1', 'Product2' and 'All Products' (Area respectively).
Now I want to drill-through from Report1 into details in Report2 by
clicking the cell containing the number. I use 'Jump to report'-navigation
and fill the parameters from Report1 matrix dataset. This works fine as
long as I start drill-through from data cell ie. click numbers 10,12,7 or
11. The problem is that also the 'Totals' appear as links, but the
parameters are not filled in correctly.
So the question is how to define the parameters in 'Jump to report' so that
when clicking Product 1 totals (22) the parameters to Report2 are set to
Product 1 - All Areas.
-pasi
--
Message posted via http://www.sqlmonster.comPlease check the MSDN documentation about the InScope function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSCREATE/htm/rcr_creating_expressions_v1_0jmt.asp
With InScope you can determine the current scope of a matrix cell and set
the drillthrough parameters accordingly. I.e. you would use an
IIF-expression to set the value of the drillthrough parameters correctly
based on the InScope return values. Note: a matrix cell is "in scope" of
column and row groupings, so you need at least two InScope function calls in
the case where you have 1 dynamic row and 1 dynamic column grouping. E.g.
=iif(InScope("ColumnGroup1"), iif(InScope("RowGroup1"), "In Cell", "In
Subtotal of RowGroup1"), iif(InScope("RowGroup1"), "In Subtotal of
ColumnGroup1", "In Subtotal of entire matrix"))
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Pasi Norrbacka via SQLMonster.com" <forum@.nospam.SQLMonster.com> wrote in
message news:dc114ab8cd48487a97ef6575f7bc7185@.SQLMonster.com...
>I have a matrix report (Report1) with rowgroup and columngroup. Both
> contain also totals (defined as group subtotals). The number of rows and
> columns varies.
> Area1 Area2 Totals
> Product 1 10 12 22
> Product 2 7 11 18
> Totals 17 23 40
> I also have another report where I can list this data more detailed
> (Report2). Report2 uses Product and Area as parameters where possible
> values are 'Product 1', 'Product2' and 'All Products' (Area respectively).
> Now I want to drill-through from Report1 into details in Report2 by
> clicking the cell containing the number. I use 'Jump to report'-navigation
> and fill the parameters from Report1 matrix dataset. This works fine as
> long as I start drill-through from data cell ie. click numbers 10,12,7 or
> 11. The problem is that also the 'Totals' appear as links, but the
> parameters are not filled in correctly.
> So the question is how to define the parameters in 'Jump to report' so
> that
> when clicking Product 1 totals (22) the parameters to Report2 are set to
> Product 1 - All Areas.
> -pasi
> --
> Message posted via http://www.sqlmonster.com|||Thanks, it works.
--
Message posted via http://www.sqlmonster.com

Friday, February 17, 2012

Drilling Down On Totals

Hi all!

I have created a report that lists a number of machine units by machine_description. There's a total at the bottom that can let you see the total number of machine units. You can also drill down on one of the units and see what stores those units are coming from. For example

No. of Units

Axles | 6

Sprockets | 5

Total | 11

You can click on the values (6 or 5) and it will return store the items and what stores they come from.

However, when you click on the total value (in this case 11) it only drills-down to the item that has been LAST returned (in this case it'll be like drillin down on the sprockets value). How can I adapt this drill-down so that it returns the units for all the parts from all the stores in the report?

Any thoughts would be greatly appreciated! Smile

I believe INSCOPE is the way to go, although I've never conquered this beast myself. If someone could give a concrete solution, that would be great.

|||

Yea,

I was JUST looking at this post a little bit later, but implementing is a little tricky.

If anyone can give a little more detail about the guys explanation that'd be great.


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

Thanks gregsql.


PS: If I do find a simpler way to explain a solution to this situation, I'll post it ASAP!

|||

I finally solved my problem. The previous posts about the INSCOPE function were very insightful. The basic breakdown is to use the INSCOPE in an IIF statement such as below -

=IIF(InScope("matrix_name"), Fields!category.Value,"ALL")

After you setup the default values for a multi-valued field for the parameters in your subreport, you can use the drill-down action from the main report to either choose a specific field/category (if TRUE parameter) and IIF this not chosen, then you can ask it to pass the parameter "ALL" (if FALSE parameter) which when passed, selects all the default values for the corresponding parameter in the subreport. Remember to setup the default values for your subreport parameters.

I hope this clears things up for a lot of people in this problem. Good luck!

|||

How does this work if it isn't a multi-valued parameter?

Something like this:

=IIF(InScope("matrix_name"), Fields!category.Value,"")

If the matrix isn't in scope then you should pass nothing to the subreport? Or what should you pass if it is just a regular parameter?

|||

Can you tell me if I am doing this correctly?

I put this in the expression for navigation:

=IIf(InScope("matrix1"),"Rev1drilldown", "Rev1")

However, it appears that regardless of whether I click the subtotal or the field in the matrix, it navigates to Rev1drilldown.

|||

I think I might know what you mean but I'm not sure. What I've done for my parameters that are not multi-valued is used an expression like this

=IIF(Parameters!category.Value = "", "ALL", Parameters!category.Value)

Of course this is assuming that this is not a dependent cascading parameter.

so if nothing is passed to the subreport, it'll default to ALL. I think you can use this WITHIN an INSCOPE function as well... something like:

=IIF(INSCOPE("matrix_name"), Fields!category.Value, IIF(Fields!category.Value = "", "ALL", Parameters!category.Value))

so this way you could pass the parameters instead or pass ALL if you needed to.

I hope I answered your question.

Drilling Down On Totals

Hi all!

I have created a report that lists a number of machine units by machine_description. There's a total at the bottom that can let you see the total number of machine units. You can also drill down on one of the units and see what stores those units are coming from. For example

No. of Units

Axles | 6

Sprockets | 5

Total | 11

You can click on the values (6 or 5) and it will return store the items and what stores they come from.

However, when you click on the total value (in this case 11) it only drills-down to the item that has been LAST returned (in this case it'll be like drillin down on the sprockets value). How can I adapt this drill-down so that it returns the units for all the parts from all the stores in the report?

Any thoughts would be greatly appreciated! Smile

I believe INSCOPE is the way to go, although I've never conquered this beast myself. If someone could give a concrete solution, that would be great.

|||

Yea,

I was JUST looking at this post a little bit later, but implementing is a little tricky.

If anyone can give a little more detail about the guys explanation that'd be great.


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

Thanks gregsql.


PS: If I do find a simpler way to explain a solution to this situation, I'll post it ASAP!

|||

I finally solved my problem. The previous posts about the INSCOPE function were very insightful. The basic breakdown is to use the INSCOPE in an IIF statement such as below -

=IIF(InScope("matrix_name"), Fields!category.Value,"ALL")

After you setup the default values for a multi-valued field for the parameters in your subreport, you can use the drill-down action from the main report to either choose a specific field/category (if TRUE parameter) and IIF this not chosen, then you can ask it to pass the parameter "ALL" (if FALSE parameter) which when passed, selects all the default values for the corresponding parameter in the subreport. Remember to setup the default values for your subreport parameters.

I hope this clears things up for a lot of people in this problem. Good luck!

|||

How does this work if it isn't a multi-valued parameter?

Something like this:

=IIF(InScope("matrix_name"), Fields!category.Value,"")

If the matrix isn't in scope then you should pass nothing to the subreport? Or what should you pass if it is just a regular parameter?

|||

Can you tell me if I am doing this correctly?

I put this in the expression for navigation:

=IIf(InScope("matrix1"),"Rev1drilldown", "Rev1")

However, it appears that regardless of whether I click the subtotal or the field in the matrix, it navigates to Rev1drilldown.

|||

I think I might know what you mean but I'm not sure. What I've done for my parameters that are not multi-valued is used an expression like this

=IIF(Parameters!category.Value = "", "ALL", Parameters!category.Value)

Of course this is assuming that this is not a dependent cascading parameter.

so if nothing is passed to the subreport, it'll default to ALL. I think you can use this WITHIN an INSCOPE function as well... something like:

=IIF(INSCOPE("matrix_name"), Fields!category.Value, IIF(Fields!category.Value = "", "ALL", Parameters!category.Value))

so this way you could pass the parameters instead or pass ALL if you needed to.

I hope I answered your question.

Drilling Down On Totals

Hi all!

I have created a report that lists a number of machine units by machine_description. There's a total at the bottom that can let you see the total number of machine units. You can also drill down on one of the units and see what stores those units are coming from. For example

No. of Units

Axles | 6

Sprockets | 5

Total | 11

You can click on the values (6 or 5) and it will return store the items and what stores they come from.

However, when you click on the total value (in this case 11) it only drills-down to the item that has been LAST returned (in this case it'll be like drillin down on the sprockets value). How can I adapt this drill-down so that it returns the units for all the parts from all the stores in the report?

Any thoughts would be greatly appreciated! Smile

I believe INSCOPE is the way to go, although I've never conquered this beast myself. If someone could give a concrete solution, that would be great.

|||

Yea,

I was JUST looking at this post a little bit later, but implementing is a little tricky.

If anyone can give a little more detail about the guys explanation that'd be great.


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

Thanks gregsql.


PS: If I do find a simpler way to explain a solution to this situation, I'll post it ASAP!

|||

I finally solved my problem. The previous posts about the INSCOPE function were very insightful. The basic breakdown is to use the INSCOPE in an IIF statement such as below -

=IIF(InScope("matrix_name"), Fields!category.Value,"ALL")

After you setup the default values for a multi-valued field for the parameters in your subreport, you can use the drill-down action from the main report to either choose a specific field/category (if TRUE parameter) and IIF this not chosen, then you can ask it to pass the parameter "ALL" (if FALSE parameter) which when passed, selects all the default values for the corresponding parameter in the subreport. Remember to setup the default values for your subreport parameters.

I hope this clears things up for a lot of people in this problem. Good luck!

|||

How does this work if it isn't a multi-valued parameter?

Something like this:

=IIF(InScope("matrix_name"), Fields!category.Value,"")

If the matrix isn't in scope then you should pass nothing to the subreport? Or what should you pass if it is just a regular parameter?

|||

Can you tell me if I am doing this correctly?

I put this in the expression for navigation:

=IIf(InScope("matrix1"),"Rev1drilldown", "Rev1")

However, it appears that regardless of whether I click the subtotal or the field in the matrix, it navigates to Rev1drilldown.

|||

I think I might know what you mean but I'm not sure. What I've done for my parameters that are not multi-valued is used an expression like this

=IIF(Parameters!category.Value = "", "ALL", Parameters!category.Value)

Of course this is assuming that this is not a dependent cascading parameter.

so if nothing is passed to the subreport, it'll default to ALL. I think you can use this WITHIN an INSCOPE function as well... something like:

=IIF(INSCOPE("matrix_name"), Fields!category.Value, IIF(Fields!category.Value = "", "ALL", Parameters!category.Value))

so this way you could pass the parameters instead or pass ALL if you needed to.

I hope I answered your question.

Drilling Down On Totals

Hi all!

I have created a report that lists a number of machine units by machine_description. There's a total at the bottom that can let you see the total number of machine units. You can also drill down on one of the units and see what stores those units are coming from. For example

No. of Units

Axles | 6

Sprockets | 5

Total | 11

You can click on the values (6 or 5) and it will return store the items and what stores they come from.

However, when you click on the total value (in this case 11) it only drills-down to the item that has been LAST returned (in this case it'll be like drillin down on the sprockets value). How can I adapt this drill-down so that it returns the units for all the parts from all the stores in the report?

Any thoughts would be greatly appreciated! Smile

I believe INSCOPE is the way to go, although I've never conquered this beast myself. If someone could give a concrete solution, that would be great.

|||

Yea,

I was JUST looking at this post a little bit later, but implementing is a little tricky.

If anyone can give a little more detail about the guys explanation that'd be great.


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

Thanks gregsql.


PS: If I do find a simpler way to explain a solution to this situation, I'll post it ASAP!

|||

I finally solved my problem. The previous posts about the INSCOPE function were very insightful. The basic breakdown is to use the INSCOPE in an IIF statement such as below -

=IIF(InScope("matrix_name"), Fields!category.Value,"ALL")

After you setup the default values for a multi-valued field for the parameters in your subreport, you can use the drill-down action from the main report to either choose a specific field/category (if TRUE parameter) and IIF this not chosen, then you can ask it to pass the parameter "ALL" (if FALSE parameter) which when passed, selects all the default values for the corresponding parameter in the subreport. Remember to setup the default values for your subreport parameters.

I hope this clears things up for a lot of people in this problem. Good luck!

|||

How does this work if it isn't a multi-valued parameter?

Something like this:

=IIF(InScope("matrix_name"), Fields!category.Value,"")

If the matrix isn't in scope then you should pass nothing to the subreport? Or what should you pass if it is just a regular parameter?

|||

Can you tell me if I am doing this correctly?

I put this in the expression for navigation:

=IIf(InScope("matrix1"),"Rev1drilldown", "Rev1")

However, it appears that regardless of whether I click the subtotal or the field in the matrix, it navigates to Rev1drilldown.

|||

I think I might know what you mean but I'm not sure. What I've done for my parameters that are not multi-valued is used an expression like this

=IIF(Parameters!category.Value = "", "ALL", Parameters!category.Value)

Of course this is assuming that this is not a dependent cascading parameter.

so if nothing is passed to the subreport, it'll default to ALL. I think you can use this WITHIN an INSCOPE function as well... something like:

=IIF(INSCOPE("matrix_name"), Fields!category.Value, IIF(Fields!category.Value = "", "ALL", Parameters!category.Value))

so this way you could pass the parameters instead or pass ALL if you needed to.

I hope I answered your question.