Showing posts with label attempt. Show all posts
Showing posts with label attempt. Show all posts

Tuesday, March 20, 2012

Comprehensive Index Information

Hi,

I am writing an in house utility to attempt to compare different
aspects of databases.
I am currently writing the queries to list all of the indexes in the
database (including primary key indexes at present - I may move these
and compare separately at some point).

I would like the following information, in one result set if possible:

Table Name
Index Name
Column Name
Column Position
Unique?

Now on Oracle, this is easily done with the following query:

SELECT IND.TABLE_NAME, IND.INDEX_NAME, IND.COLUMN_NAME,
IND.COLUMN_POSITION, COL.UNIQUENESS
FROM USER_IND_COLUMNS IND,
USER_INDEXES COL
WHEREIND.INDEX_NAME = COL.INDEX_NAME
ORDER BY 1, 2, 3, 4, 5

I have been trying for over an hour now to get the equivalent, and I
really cannot figure it out. If anybody can come up with this then I
would greatly appreciate it!

Many Thanks,

PaulPaul (paulwragg2323@.hotmail.com) writes:

Quote:

Originally Posted by

I am writing an in house utility to attempt to compare different
aspects of databases.


Before you go too far, pay a visit to http://www.red-gate.com and
if SQL Compare meets your needs.

Quote:

Originally Posted by

I am currently writing the queries to list all of the indexes in the
database (including primary key indexes at present - I may move these
and compare separately at some point).
>
I would like the following information, in one result set if possible:
>
Table Name
Index Name
Column Name
Column Position
Unique?


SELECT tablename = t.name, indexname = i.name,
colname = c.name, pos = ic.index_column_id,
indextype = i.type_desc, isunique = i.is_unique
FROM sys.tables t
JOIN sys.indexes i ON t.object_id = i.object_id
JOIN sys.index_columns ic ON i.object_id = ic.object_id
AND i.index_id = ic.index_id
JOIN sys.columns c ON t.object_id = c.object_id
AND ic.column_id = c.column_id
WHERE i.is_hypothetical = 0

There are probably more columns should include in the output, but I
levae that as an exercise.

Note: the above works in SQL 2005 only. Next time, please specify which
version of SQL Server you are using.

--
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 Erland,

Thankyou very much for this. Of course, as usual I stupidly forgot to
post the version. Sorry about that. Really I need something that will
work on both SQL Server 2000 and SQL Server 2005.

Thanks for the link - unfortunately this is more of an exercise for
the time being and so we are not willing to spend money on a tool at
present!

Thanks for the help - if you do know something that will work on both
versions that would be good.

Paul|||Paul (paulwragg2323@.hotmail.com) writes:

Quote:

Originally Posted by

Thankyou very much for this. Of course, as usual I stupidly forgot to
post the version. Sorry about that. Really I need something that will
work on both SQL Server 2000 and SQL Server 2005.


Then you need to work against sysobjects, sysindexes, sysindexkeys and
syscolumns. The query will be similar, but you need to filter for
statistics, since in SQL 2000 statistics and indexes live in sysindexes.

These are documented in Books Online, and since this is an exercise for you,
I leave you there. :-)

--
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|||Thanks Erland.

Friday, February 24, 2012

Complex IIF statement not working

I am not understanding what my issue is on this one! I can look at the data
returned from the dataset in Data view, but when I attempt to show a table
based on at least one value being true (from several) it says:
"The hidden expression for the table 'table1' refers to the field
'SSFLunchRegular'. Report item expressions can only refer to fields within
the current data set scope..."
I can turn right around and show/hide a row of the table based on the exact
same field name and it works. The structure of my IIF statment appears to be
fine because the same structure works in another report. Is it the number of
conditions? Is there a limit?
Here are the conditions placed on the Hidden statement:
=IIF(
(FIELDS!SLPLunchRegular.Value <> 0) and
(FIELDS!SLPLunchProv1.Value <> 0) and
(FIELDS!SLPLunchProv2.Value <> 0) and
(FIELDS!SLPLunchProv3.Value <> 0) and
(FIELDS!SLPBkfstRegular.Value <> 0) and
(FIELDS!SLPBkfstProv1.Value <> 0) and
(FIELDS!SLPBkfstProv2.Value <> 0) and
(FIELDS!SLPBkfstProv3.Value <> 0) and
(FIELDS!SLPSevereRegular.Value <> 0) and
(FIELDS!SLPSevereProv1.Value <> 0) and
(FIELDS!SLPSevereProv2.Value <> 0) and
(FIELDS!SLPSevereProv3.Value <> 0) and
(FIELDS!SLPSnackArea.Value <> 0) and
(FIELDS!SLPSnackNonArea.Value <> 0), False, True
)
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1oops, I wrote 'SSFLunchRegular', it should have been 'SLPLunchRegular'. The
misspelling was in this thread, not my code so the problem is not solved..
Rick wrote:
>I am not understanding what my issue is on this one! I can look at the data
>returned from the dataset in Data view, but when I attempt to show a table
>based on at least one value being true (from several) it says:
>"The hidden expression for the table 'table1' refers to the field
>'SSFLunchRegular'. Report item expressions can only refer to fields within
>the current data set scope..."
>I can turn right around and show/hide a row of the table based on the exact
>same field name and it works. The structure of my IIF statment appears to be
>fine because the same structure works in another report. Is it the number of
>conditions? Is there a limit?
>Here are the conditions placed on the Hidden statement:
>=IIF(
>(FIELDS!SLPLunchRegular.Value <> 0) and
>(FIELDS!SLPLunchProv1.Value <> 0) and
>(FIELDS!SLPLunchProv2.Value <> 0) and
>(FIELDS!SLPLunchProv3.Value <> 0) and
>(FIELDS!SLPBkfstRegular.Value <> 0) and
>(FIELDS!SLPBkfstProv1.Value <> 0) and
>(FIELDS!SLPBkfstProv2.Value <> 0) and
>(FIELDS!SLPBkfstProv3.Value <> 0) and
>(FIELDS!SLPSevereRegular.Value <> 0) and
>(FIELDS!SLPSevereProv1.Value <> 0) and
>(FIELDS!SLPSevereProv2.Value <> 0) and
>(FIELDS!SLPSevereProv3.Value <> 0) and
>(FIELDS!SLPSnackArea.Value <> 0) and
>(FIELDS!SLPSnackNonArea.Value <> 0), False, True
>)
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1|||The problem seems to be that you're attempting to hide a whole table based
on one single record. That wouldn't be logical. You'd need to aggregate the
values somehow, something like
=IIF(
(Sum(FIELDS!SLPLunchRegular.Value) <> 0) and
(Sum(FIELDS!SLPLunchProv1.Value) <> 0) and
...
...
Hope this helps.
--
Robert Jeppesen
Durius
http://www.durius.com/
"Rick via SQLMonster.com" <u15024@.uwe> wrote in message
news:5773f7edc9ca2@.uwe...
>I am not understanding what my issue is on this one! I can look at the
>data
> returned from the dataset in Data view, but when I attempt to show a table
> based on at least one value being true (from several) it says:
> "The hidden expression for the table 'table1' refers to the field
> 'SSFLunchRegular'. Report item expressions can only refer to fields
> within
> the current data set scope..."
> I can turn right around and show/hide a row of the table based on the
> exact
> same field name and it works. The structure of my IIF statment appears to
> be
> fine because the same structure works in another report. Is it the number
> of
> conditions? Is there a limit?
> Here are the conditions placed on the Hidden statement:
> =IIF(
> (FIELDS!SLPLunchRegular.Value <> 0) and
> (FIELDS!SLPLunchProv1.Value <> 0) and
> (FIELDS!SLPLunchProv2.Value <> 0) and
> (FIELDS!SLPLunchProv3.Value <> 0) and
> (FIELDS!SLPBkfstRegular.Value <> 0) and
> (FIELDS!SLPBkfstProv1.Value <> 0) and
> (FIELDS!SLPBkfstProv2.Value <> 0) and
> (FIELDS!SLPBkfstProv3.Value <> 0) and
> (FIELDS!SLPSevereRegular.Value <> 0) and
> (FIELDS!SLPSevereProv1.Value <> 0) and
> (FIELDS!SLPSevereProv2.Value <> 0) and
> (FIELDS!SLPSevereProv3.Value <> 0) and
> (FIELDS!SLPSnackArea.Value <> 0) and
> (FIELDS!SLPSnackNonArea.Value <> 0), False, True
> )
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1