Showing posts with label contains. Show all posts
Showing posts with label contains. Show all posts

Monday, March 26, 2012

Matrix: Hide null value row

The matrix that i have contains null values and is creating empty rows. I tried grouping the row and then setting the visible property, but that just hides the entire rows. Is there an expression that i would need to ensure that only the null rows are not visible on the matrix?

Thanks for taking the time to read.

The database tables looks like:

Month Sales Product

- - --

August 2007 700.00 Apples

August 2007 400.00 Oranges
September 2007 380.00 Apples
October 2007 1200.00 Oranges
November 2007 NULL NULL
December 2007 NULL NULL
Jan 2008 400.00 Grapefruit

The matrix looks like:

August 2007 Sept 2007 Oct 2007 Nov 2007 Dec 2007 Jan 2008

Apples 700.00 380.00

Oranges 400.00 1200.00

Grapfruit 400.00

Try filtering these records. You can use the filter within the Matrix properties to filter all records where Product Names are NULL

|||

I actually tried filtering in the edit group searching for nulls but it didn't work.

I did a bit of searching and found that i needing to use this: =IsNothing(Fields!productname.Value) in the filter expression for the group.

Thanks for your help.sql

Friday, March 23, 2012

Matrix with fixed column values (months 1-12)

I have a matrix that shows sales per year (rows) and month (columns).
If the data being used contains no records for a particular month for any
year (e.g. November), that column (i.e. column 11) is completely missing
from the matrix.
Can the matrix be configured to always show a given set of columns, even if
there is no underlying data?
ThanksHi Laurence,
If you don't have any data rows for a certain month, then it will not show
up in the matrix grouping. To ensure that certain groups/data values are
always present, you will need an outer join in your dataset query e.g. with
a simple table that just has 12 rows with one column and values from 1 to
12.
Details on how to use outer joins are available here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_09_0zqr.asp
http://msdn.microsoft.com/library/en-us/acdata/ac_8_qd_09_1h6b.asp
HTH,
Robert
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Laurence Neville" <laurenceneville@.hotmail.com> wrote in message
news:O8YpoRDuEHA.1296@.TK2MSFTNGP10.phx.gbl...
> I have a matrix that shows sales per year (rows) and month (columns).
> If the data being used contains no records for a particular month for any
> year (e.g. November), that column (i.e. column 11) is completely missing
> from the matrix.
> Can the matrix be configured to always show a given set of columns, even
if
> there is no underlying data?
> Thanks
>|||OK thanks, I know how to do that.
"Robert Bruckner [MSFT]" <robruc@.online.microsoft.com> wrote in message
news:uWTPFZyuEHA.3228@.TK2MSFTNGP12.phx.gbl...
> Hi Laurence,
> If you don't have any data rows for a certain month, then it will not show
> up in the matrix grouping. To ensure that certain groups/data values are
> always present, you will need an outer join in your dataset query e.g.
> with
> a simple table that just has 12 rows with one column and values from 1 to
> 12.
> Details on how to use outer joins are available here:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_qd_09_0zqr.asp
> http://msdn.microsoft.com/library/en-us/acdata/ac_8_qd_09_1h6b.asp
> HTH,
> Robert
> --
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> "Laurence Neville" <laurenceneville@.hotmail.com> wrote in message
> news:O8YpoRDuEHA.1296@.TK2MSFTNGP10.phx.gbl...
>> I have a matrix that shows sales per year (rows) and month (columns).
>> If the data being used contains no records for a particular month for any
>> year (e.g. November), that column (i.e. column 11) is completely missing
>> from the matrix.
>> Can the matrix be configured to always show a given set of columns, even
> if
>> there is no underlying data?
>> Thanks
>>
>

Matrix SubTotals

The data cell contains '=iif( Fields!dt.Value <
#11/1/2004#,"*",Sum(Fields!MyValue.Value))' which is causing the subtotals
(row & column) to show an * whenever the row or column shows an *.
How do I get the subtotal to ignore the *'s and subtotal on just those cells
that contain a value.I discovered that the subtotals cell is using the Fields!dt.Value from the
first matrix column, and since the columns are sorted oldest dt to newest the
dt.Value is < the date indicated.
Can someone think of a way I can fix this other the changing the column order?
"Harolds" wrote:
> The data cell contains '=iif( Fields!dt.Value <
> #11/1/2004#,"*",Sum(Fields!MyValue.Value))' which is causing the subtotals
> (row & column) to show an * whenever the row or column shows an *.
> How do I get the subtotal to ignore the *'s and subtotal on just those cells
> that contain a value.|||I changed my iif to =iif(last(Fields!dt.Value)... and this fixed my problem.
"Harolds" wrote:
> The data cell contains '=iif( Fields!dt.Value <
> #11/1/2004#,"*",Sum(Fields!MyValue.Value))' which is causing the subtotals
> (row & column) to show an * whenever the row or column shows an *.
> How do I get the subtotal to ignore the *'s and subtotal on just those cells
> that contain a value.

Wednesday, March 21, 2012

Matrix sorting

Hi. I need to implement a matrix that supports column sorting just like a table.
For example, given a matrix that contains...

Col1 Col2
Row1 1 8
Row2 2 6
Row3 3 7

...if the user clicks on "Col2", I need the matrix to look like this:

Col1 Col2
Row2 2 6
Row3 3 7
Row1 1 8

I cannot use the interactive sort feature since the matrix must be WYSIWYG with the printed copy and the built-in interactive sort arrows do appear in printed output.

Here's my partial solution; my hope is that someone can point me in the right direction from here:

When the user clicks on a column heading I will jump to a URL such as:
http://myserver/myreport.aspx?SortField=Col2&SortDirection=Ascending

SortField and SortDirection are parsed by the web app and passed as parameters to my report.

So, after the user clicks on Col2 the report knows the following:
Parameters!SortField.Value = "Col2"
and
Parameters!SortDirection.Value = "Ascending"

Given this information, is there a way to tell the report's matrix to actually display the data in the order shown in the example above.

Thanks for any help you can provide.
Try right click on matrix and select matrix properties, select groups, select edit matrix group, select the sorting tab, change the expression value should be col 12 and direction descending. It worked for me.

Friday, March 9, 2012

Matrix Aggregation to a Column only

Hello,
I have a matrix report displaying data from a data cube, via analysis
services. It contains column groupings for Months, Quarters and Year as well
as row groups for Team, User and Region. This allows the user to drill down
from a top level "All Teams" total for the whole year, down to a full view of
a region for a particular month.
To achieve this, the "Sum" function is used to aggregate the figures. But,
we wish to also use a running total of Sales by region using Brought Forward
and Carried Forward balances. This needs to be aggregated by column (region
to user to team), but not by row. (Otherwise the Jan, Feb and March totals
are added together for example for Q1, which is incorrect).
Is there a way to specify the axis for the Sum function? Or another way to
create the report that still allows the drill-down/up functionality?
Many Thanks.
Ben Mann.Although I don't understand the business part of your question... Matrix
allows aggregations to be done on rows OR columns... It looks like you
wanted some aggregation on both axes... Matrixes can do this...
Also you can use any of the aggregate functions that RS supports, take a
look at runningvalue... that might be what you are lookin for...
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Ben Mann" <Ben Mann@.discussions.microsoft.com> wrote in message
news:37B6B96A-FF6F-4D63-A820-B6E588C13233@.microsoft.com...
> Hello,
> I have a matrix report displaying data from a data cube, via analysis
> services. It contains column groupings for Months, Quarters and Year as
well
> as row groups for Team, User and Region. This allows the user to drill
down
> from a top level "All Teams" total for the whole year, down to a full view
of
> a region for a particular month.
> To achieve this, the "Sum" function is used to aggregate the figures. But,
> we wish to also use a running total of Sales by region using Brought
Forward
> and Carried Forward balances. This needs to be aggregated by column
(region
> to user to team), but not by row. (Otherwise the Jan, Feb and March totals
> are added together for example for Q1, which is incorrect).
> Is there a way to specify the axis for the Sum function? Or another way to
> create the report that still allows the drill-down/up functionality?
> Many Thanks.
> Ben Mann.

Saturday, February 25, 2012

Matching records within same table

Hi all,

I've got a table named tLogonInfo with the following fields: fLogType, fDeskID, fUsername, fEventDate.

This table contains the logon and logoff history of an application. So for example the table could contain the following records:

1. 'Logon', '1', 'Jack', '2007-7-15 13:00:00'

2. 'Logon', '3', 'Paul', '2007-7-15 13:22:00'

3. 'Logoff', '1', 'Jack', '2007-7-15 14:00:00'

4. 'Logon', '2', 'Jack', '2007-7-16 10:30:00'

5. 'Logoff', '3', 'Paul', '2007-7-16 11:12:00'

6. 'Logoff', '2', 'Jack', '2007-7-16 17:10:00'

I want to make a query that has the fields Desk, User, Logon, Logoff and has the following result:

1. '1', 'Jack', '2007-7-15 13:00:00', '2007-7-15 14:00:00'

2. '3', 'Paul', '2007-7-15 13:22:00', '2007-7-16 11:12:00'

3. '2', 'Jack', '2007-7-16 10:30:00', '2007-7-16 17:10:00'

How can I do this?

if you use sql server 2005,

Code Snippet

Create Table #logindata (

[Operation] Varchar(100) ,

[Mac] Varchar(100) ,

[User] Varchar(100) ,

[OperDateTime] Varchar(100)

);

Insert Into #logindata Values('Logon','1','Jack','2007-7-15 13:00:00');

Insert Into #logindata Values('Logon','3','Paul','2007-7-15 13:22:00');

Insert Into #logindata Values('Logoff','1','Jack','2007-7-15 14:00:00');

Insert Into #logindata Values('Logon','2','Jack','2007-7-16 10:30:00');

Insert Into #logindata Values('Logoff','3','Paul','2007-7-16 11:12:00');

Insert Into #logindata Values('Logoff','2','Jack','2007-7-16 17:10:00');

;With Ordered as

(

Select

*

, Row_Number() Over(Partition By [User],[Mac] Order By [User],[Mac], [OperDateTime]) OpId

From

#logindata

)

Select

Logon.[User], LogOn.Mac, Logon.OperDateTime [Logon Time], Logoff.OperDateTime [Logoff Time]

from Ordered Logon

Left Outer Join Ordered Logoff On

Logon.[User] = Logoff.[User]

and Logon.[Mac] = Logoff.[Mac]

and Logon.OpId = Logoff.OpId -1

Where

Logon.Operation='Logon'

and Logoff.Operation='Logoff'

Drop table #logindata

|||

For SQL Server 2000,

Code Snippet

Create Table #logindata (

[Operation] Varchar(100) ,

[Mac] Varchar(100) ,

[User] Varchar(100) ,

[OperDateTime] Varchar(100)

);

Insert Into #logindata Values('Logon','1','Jack','2007-7-15 13:00:00');

Insert Into #logindata Values('Logon','3','Paul','2007-7-15 13:22:00');

Insert Into #logindata Values('Logoff','1','Jack','2007-7-15 14:00:00');

Insert Into #logindata Values('Logon','2','Jack','2007-7-16 10:30:00');

Insert Into #logindata Values('Logoff','3','Paul','2007-7-16 11:12:00');

Insert Into #logindata Values('Logoff','2','Jack','2007-7-16 17:10:00');

Select

[user],

[mac],

[OperDateTime] as [Logon Time],

(Select Min([OperDateTime])

From #logindata Sub Where

[Operation]='Logoff'

And Sub.[user]=Main.[user]

And Sub.[mac]=Main.[mac]) as [Logoff Time]

from #logindata Main

Where

[Operation]='Logon'

Drop table #logindata

Matching on from a list

HI,

say I have a list from an sql statement (results list)
this list contains 10 items

In another table, in one particular column - there is a match for one of these items from the initial list.

SO... this may be the list
_____________________
itemnumber
1
2
3
4
5
6
7
8
9
10
----------

in the other table there is a match...
but just for one item on that list.
____________________
othertablefield
11
13
14
3 <-- match
99
78
---------

How do I find that match with my sql statement?SELECT [Othertablefield] FROM Table2 WHERE [Othertablefield] NOT IN (SELECT [itemnumber] FROM Table1)

HTH

Matching Columns

All

I have a table which contains 4 columns each of which are NULL or contain a 6 digit code.
Here is a sample of the table content:

COL1 COL2 COL3 COL4
-- -- -- --
452359 NULL NULL 347406
NULL NULL 347406 347406
592319 NULL 347406 347406
592319 150009 347406 347406
592319 150010 347406 347406

Through out the table any number of the columns can be null.

I wish to remove rows from this table where the columns values are contained in another row i.e Row 2 above is contained within row 3. Similarly, row 3 is contained within row 4.
So, the only rows I want from the sample data above are rows 1, 4 and 5.

I hope I have explained my query adequately, and any help would be great appreciated. (Before I go mad...!)

Regards,
KatherineYou'll have to test this carefully, but I'd use something like:DELETE FROM foo
WHERE (Col1 IS NULL OR Col2 IS NULL OR Col3 IS NULL OR Col4 IS NULL)
AND EXISTS (SELECT *
FROM foo AS b
WHERE b.Col1 = Coalesce(foo.Col1, b.Col1)
AND b.Col2 = Coalesce(foo.Col2, b.Col2)
AND b.Col3 = Coalesce(foo.Col3, b.Col3)
AND b.Col4 = Coalesce(foo.Col4, b.Col4))-PatP|||pat: sorry: :)
insert...
select 123, null, null, null
union
select null, 123, null, null
union
select 123, 123, null, null

gives:
col1 col2 col3 col4
---- ---- ---- ----
NULL 123 NULL NULL
123 NULL NULL NULL
123 123 NULL NULL

Turns out it's a nice challenge, at least for me...|||I know there *has* to be a better way to do this... but here goes.

create table test (a int null, b int null, c int null, d int null)

insert into test(a,b,c,d)
select 123, null, null, null
union
select null, 123, null, null
union
select 123, 123, null, null

delete from t1
from test t1
inner join test t2
on (t1.a is null or t1.a=t2.a)
and (t1.b is null or t1.b=t2.b)
and (t1.c is null or t1.c=t2.c)
and (t1.d is null or t1.d=t2.d)
where
(
((t1.a!=t2.a and (t1.a is not null and t2.a is not null)) or (t1.a is null and t2.a is not null) or (t1.a is not null and t2.a is null))
or ((t1.b!=t2.b and (t1.b is not null and t2.b is not null)) or (t1.b is null and t2.b is not null) or (t1.b is not null and t2.b is null))
or ((t1.c!=t2.c and (t1.c is not null and t2.c is not null)) or (t1.c is null and t2.c is not null) or (t1.c is not null and t2.c is null))
or ((t1.d!=t2.d and (t1.d is not null and t2.d is not null)) or (t1.d is null and t2.d is not null) or (t1.d is not null and t2.d is null))
)

You'd have to run a dedup after this if you've got duplicate rows.
That ugly WHERE is just killin' me, but dealing with the NULLs is a real PITA.|||I tried it by creating a new table, inserting those with the least nulls then winding up to the most nulls skipping those with matching values. The way I have it now is a real pain and doesn't work properly.. so...|||Like a lot of tricky SQL problems, the issue here is not the question you are asking, but the fact that your schema is not normalized. Fix it, if at all possible, or you are sure to run into more problems in the future.

This method solves your problem but normalizing your data into a temporary table, and then searching the temporary table for record groups that are a subset of other record groups. It presupposes that you have a unique primary key in your original table.

DECLARE @.TEMPNORMAL TABLE
(PKEY INT,
COLVALUE VARCHAR(6))

DECLARE @.PKEYITEMCOUNT TABLE
(PKEY INT,
ITEMCOUNT INT)

INSERT INTO @.TEMPNORMAL
(PKEY,
COLVALUE)
SELECT DISTINCT
PKEY,
COLVALUE
FROM
(Select PKEY, COL1 as COLVALUE from YOURTABLE
UNION
Select PKEY, COL2 as COLVALUE from YOURTABLE
UNION
Select PKEY, COL3 as COLVALUE from YOURTABLE
UNION
Select PKEY, COL4 as COLVALUE from YOURTABLE) NORMALTRANSFORM

INSERT INTO @.PKEYITEMCOUNT
(PKEY,
ITEMCOUNT)
SELECT PKEY,
COUNT(*)
FROM @.TEMPNORMAL
GROUP BY PKEY

DELETE
FROM YOURTABLE
INNER JOIN
(SELECT PKEY
FROM @.PKEYITEMCOUNT PKEYITEMCOUNT1
INNER JOIN
(SELECT PKEY1,
PKEY2,
COUNT(*) MATCHCOUNT
FROM (SELECT DISTINCT
TEMPNORMAL1.PKEY PKEY1,
TEMPNORMAL2.PKEY PKEY2,
TEMPNORMAL1.COLVALUE
FROM @.TEMPNORMAL TEMPNORMAL1
INNER JOIN @.TEMPNORMAL TEMPNORMAL2
ON TEMPNORMAL1.COLVALUE = TEMPNORMAL2.COLVALUE
AND TEMPNORMAL1.PKEY <> TEMPNORMAL2.PKEY) MATCHQUERY
GROUP BY PKEY1,
PKEY2) PKEYMATCHES
ON PKEYITEMCOUNT.PKEY = PKEYMATCHES.PKEY
AND PKEYITEMCOUNT.ITEMCOUNT = PKEYMATCHES.MATCHCOUNT
INNER JOIN @.PKEYITEMCOUNT PKEYITEMCOUNT2
ON PKEYMATCHES.PKEY2 = PKEYITEMCOUNT2.PKEY
AND PKEYITEMCOUNT1.ITEMCOUNT < PKEYITEMCOUNT2.ITEMCOUNT) SUPERFLUOUSRECORDS
ON YOURTABLE.PKEY = SUPERFLUOUSRECORDS.PKEY

blindman|||Oops...insert statement should read like this:

INSERT INTO @.TEMPNORMAL
(PKEY,
COLVALUE)
SELECT DISTINCT
PKEY,
COLVALUE
FROM
(Select PKEY, COL1 as COLVALUE from YOURTABLE where COL1 is not null
UNION
Select PKEY, COL2 as COLVALUE from YOURTABLE where COL1 is not null
UNION
Select PKEY, COL3 as COLVALUE from YOURTABLE where COL1 is not null
UNION
Select PKEY, COL4 as COLVALUE from YOURTABLE where COL1 is not null) NORMALTRANSFORM

Monday, February 20, 2012

Master..sysaltfiles contains incorrect info

Dear all,
I had a database which contained 2 log files, one of the log files was
deleted - however, master..sysaltfiles still shows 2 log files in
existance...
The database is open, and working OK, so second log file is definately not
being used ( it no longer exists on disk)...
So how do I update master..sysaltfiles to be correct ?
I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows 2
files) . I'm loathe to do a direct delete on master..sysaltfiles until I can
discover if this kind of 'corruption' is not unknown... but do I have any
other choice ?
Hi
I don't know why you have got the extra entry, was there any message in the
SQL Server log when you re-started?
What happens when you try to remove the file using:
ALTER DATABASE database REMOVE FILE logical_file_name
John
"SteveH" <SteveH@.discussions.microsoft.com> wrote in message
news:7C75A085-7563-4D94-9E50-353ECAFF820B@.microsoft.com...
> Dear all,
> I had a database which contained 2 log files, one of the log files was
> deleted - however, master..sysaltfiles still shows 2 log files in
> existance...
> The database is open, and working OK, so second log file is definately not
> being used ( it no longer exists on disk)...
> So how do I update master..sysaltfiles to be correct ?
> I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows
> 2
> files) . I'm loathe to do a direct delete on master..sysaltfiles until I
> can
> discover if this kind of 'corruption' is not unknown... but do I have any
> other choice ?

Master..sysaltfiles contains incorrect info

Dear all,
I had a database which contained 2 log files, one of the log files was
deleted - however, master..sysaltfiles still shows 2 log files in
existance...
The database is open, and working OK, so second log file is definately not
being used ( it no longer exists on disk)...
So how do I update master..sysaltfiles to be correct ?
I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows 2
files) . I'm loathe to do a direct delete on master..sysaltfiles until I can
discover if this kind of 'corruption' is not unknown... but do I have any
other choice ?Hi
I don't know why you have got the extra entry, was there any message in the
SQL Server log when you re-started?
What happens when you try to remove the file using:
ALTER DATABASE database REMOVE FILE logical_file_name
John
"SteveH" <SteveH@.discussions.microsoft.com> wrote in message
news:7C75A085-7563-4D94-9E50-353ECAFF820B@.microsoft.com...
> Dear all,
> I had a database which contained 2 log files, one of the log files was
> deleted - however, master..sysaltfiles still shows 2 log files in
> existance...
> The database is open, and working OK, so second log file is definately not
> being used ( it no longer exists on disk)...
> So how do I update master..sysaltfiles to be correct ?
> I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows
> 2
> files) . I'm loathe to do a direct delete on master..sysaltfiles until I
> can
> discover if this kind of 'corruption' is not unknown... but do I have any
> other choice ?

Master..sysaltfiles contains incorrect info

Dear all,
I had a database which contained 2 log files, one of the log files was
deleted - however, master..sysaltfiles still shows 2 log files in
existance...
The database is open, and working OK, so second log file is definately not
being used ( it no longer exists on disk)...
So how do I update master..sysaltfiles to be correct ?
I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows 2
files) . I'm loathe to do a direct delete on master..sysaltfiles until I can
discover if this kind of 'corruption' is not unknown... but do I have any
other choice ?Hi
I don't know why you have got the extra entry, was there any message in the
SQL Server log when you re-started?
What happens when you try to remove the file using:
ALTER DATABASE database REMOVE FILE logical_file_name
John
"SteveH" <SteveH@.discussions.microsoft.com> wrote in message
news:7C75A085-7563-4D94-9E50-353ECAFF820B@.microsoft.com...
> Dear all,
> I had a database which contained 2 log files, one of the log files was
> deleted - however, master..sysaltfiles still shows 2 log files in
> existance...
> The database is open, and working OK, so second log file is definately not
> being used ( it no longer exists on disk)...
> So how do I update master..sysaltfiles to be correct ?
> I restarted SQL Server, did not resolve issue ( ie sysaltfiles still shows
> 2
> files) . I'm loathe to do a direct delete on master..sysaltfiles until I
> can
> discover if this kind of 'corruption' is not unknown... but do I have any
> other choice ?