Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

Thursday, March 22, 2012

BUG? or intended that in order to move or rename reports....

...anywhere in the folder structure a person must be set up as a Content Manager at the Reporting Services ROOT (and at every level of the folder hierarchy down to the level that they are moving/renaming)?

Sure, you can remove them from the role in other folders where they should not be moving or renaming objects, but it seems you still have to have them at the root (and down the chain), which gives them far more capabilities than you might intend.

Jeff

After further examination into this problem, it appears in order for someone to move or rename a report or file, they need two things:

1) Content Manager role for the folder they are moving to/from or renaming files

2) Content Manager role for the root RS folder, but not up or down the chain between the root or the folder above.

This has really got to be a bug, as I can't imagine Microsoft doing this on purpose.

Jeff

Sunday, March 11, 2012

Bug in SELECT TOP (100) PERCENT with ORDER BY in SQLExpress?

I have a problem with the following query in SQLExpress:

SELECT TOP (100) PERCENT ClientSurname, ClientName
FROM dbo.Client
ORDER BY ClientSurname, ClientName

The query returns always assorted data ignoring the ORDER BY keyword, no matter if the query is invoked directly from Management Studio Express CTP as a View, Table-valued function or called from an Access ADP project. The result is always assorted.

Now an interesting thing is that the syntax below returns always an expected order:

SELECT TOP (99) PERCENT
SELECT TOP 10000

Am I missing something or is it a bug in SQLExpress?I never use the brackets (parenthesis) around the percentage. Maybe your second example is just using the top 10000 (not the 99%) and sorting your recs as you expect.

Keeping in mind that I know nothing of this SQLExpress :)|||TOP is a function, not a predicate as it used to be in 2K.

Thursday, March 8, 2012

Bug in evaluation order (or am I wrong?)

Hello,
I have been using sql server for many years and have always been happy with
it (and I am still). I have been totally surprised when I discover a bug
yesterday.
You may not call it a bug but it's at least an unexpected comportment from
my developer's point of view.
Here is how to reproduce :
-- STATEMENT 1
select ISNULL(null, 'Result if null')
-- Returns 'Result if null', I am OK
-- STATEMENT 2
select right(null, 5)
-- Returns NULL, I am OK
-- STATEMENT 3
select ISNULL(right(null, 5), 'Result if null')
-- As I have just replaced null value of the STATEMENT 1
-- with the STATEMENT 2 (also evaluated as null) I am expecting
-- to get the same result as STATEMENT 1 but instead I get an empty
string...?
-- STATEMENT 4
select right(CONVERT(varchar, null), 5)
--> Returns NULL, I am OK
select ISNULL(right(CONVERT(varchar, null), 5), 'Result if null')
-- As I have just replaced null value of the STATEMENT 1
-- with the STATEMENT 4 (also evaluated as null) I am expecting
-- to get the same result as STATEMENT 1 or at least an empty
-- string like STATEMENT 3, but instead I get 'Resul'...?
I would be glad if someone could explain me.
For info I am using SQL server 2000 sp3.
Many thanks,
Guirec Le Bars.ISNULL invariably returns the datatype of its first argument. In your
STATEMENT 3 you haven't specified a type for the first argument. The
NULL keyword is typless so the RIGHT expression implictly converts it
and returns a zero length string. That means the second argument is
also implicitly converted to a zero length string and that is the
result you see.
Note that if you change ISNULL to COALESCE you will get the full string
returned: 'Result if null'. That's because COALESCE, unlike ISNULL,
uses the type precedence rules to determine what type to return.
The return types are documented in the ISNULL and COALESCE topics in
BOL. Precedence is documented under the Datatype Precedence topic.
Similarly
select ISNULL(right(CONVERT(varchar, null), 5), 'Result if null')
truncates the string because the first argument determines the type and
size. Again, change ISNULL to COALESCE and you'll get the whole string.
The theme here is Implicit Conversion. Avoid implicit conversions
wherever possible by specifying the datatypes explicitly - that
includes when using the NULL keyword.
David Portas
SQL Server MVP
--|||then what should be the result of this
select ISNULL(right(null, 25), 100)
A surprise
--
Regards
R.D
--Knowledge gets doubled when shared
"David Portas" wrote:

> ISNULL invariably returns the datatype of its first argument. In your
> STATEMENT 3 you haven't specified a type for the first argument. The
> NULL keyword is typless so the RIGHT expression implictly converts it
> and returns a zero length string. That means the second argument is
> also implicitly converted to a zero length string and that is the
> result you see.
> Note that if you change ISNULL to COALESCE you will get the full string
> returned: 'Result if null'. That's because COALESCE, unlike ISNULL,
> uses the type precedence rules to determine what type to return.
> The return types are documented in the ISNULL and COALESCE topics in
> BOL. Precedence is documented under the Datatype Precedence topic.
> Similarly
> select ISNULL(right(CONVERT(varchar, null), 5), 'Result if null')
> truncates the string because the first argument determines the type and
> size. Again, change ISNULL to COALESCE and you'll get the whole string.
> The theme here is Implicit Conversion. Avoid implicit conversions
> wherever possible by specifying the datatypes explicitly - that
> includes when using the NULL keyword.
> --
> David Portas
> SQL Server MVP
> --
>|||Hi David,
What you are telling me is that NULL and right(NULL , 5) and
right(CONVERT(varchar, NULL), 5) are of 3 different datatypes even if they
are all evaluated as NULL values?
You can imagine that I consider this as an unexpected behavior...
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1128589655.573516.172420@.z14g2000cwz.googlegroups.com...
> ISNULL invariably returns the datatype of its first argument. In your
> STATEMENT 3 you haven't specified a type for the first argument. The
> NULL keyword is typless so the RIGHT expression implictly converts it
> and returns a zero length string. That means the second argument is
> also implicitly converted to a zero length string and that is the
> result you see.
> Note that if you change ISNULL to COALESCE you will get the full string
> returned: 'Result if null'. That's because COALESCE, unlike ISNULL,
> uses the type precedence rules to determine what type to return.
> The return types are documented in the ISNULL and COALESCE topics in
> BOL. Precedence is documented under the Datatype Precedence topic.
> Similarly
> select ISNULL(right(CONVERT(varchar, null), 5), 'Result if null')
> truncates the string because the first argument determines the type and
> size. Again, change ISNULL to COALESCE and you'll get the whole string.
> The theme here is Implicit Conversion. Avoid implicit conversions
> wherever possible by specifying the datatypes explicitly - that
> includes when using the NULL keyword.
> --
> David Portas
> SQL Server MVP
> --
>|||Same principle applies but in this case the implicit conversion and
truncation of a numeric is displayed as an asterisk, as happens with
any conversion of a numeric to a string of insufficient length. Verify
the return type like this:
SELECT ISNULL(RIGHT(NULL, 25), 100) AS x INTO T
Result:
Server: Msg 2731, Level 16, State 1, Line 1
Column 'x' has invalid width: 0.
Apparently in your original query the return type is then implicitly
cast to a non-zero length string for display. That's an interesting
feature but not especially important I think because any non-trivial
use of that expression would require a conversion to some other usable
datatype anyway.
David Portas
SQL Server MVP
--|||You have to distinguish between the NULL *keyword* and the "value" of
NULL (strictly NULL isn't a proper value at all but for brevity I'm
calling it such here). NULL values are valid in any datatype but the
keyword "NULL" isn't a value at all - it's just a literal keyword that
can be used to generate NULL values in expressions. When an expression
contains the NULL keyword the actual datatype returned is determined by
the other parts of the expression. This is to be expected, given the
nature of SQL's typing. Otherwise we would need separate keywords for
each type of NULL (or the language could disallow the use of the NULL
keyword without an explicit "constructor" function, which would perhaps
be a better solution).
So yes, of course there are many possible datatypes for a NULL value.
If there were not then NULLs would be unusable. Your confusion comes
from the fact that you are using implicit conversion in your
expressions. Implicit conversion is the root of many programming errors
and should generally be avoided.
David Portas
SQL Server MVP
--|||Yes, there are a lot of NULL related issues that are unexpected in SQL.
Quite often it is hard to make any sense out of it, but most of us are ok
with "just do it, that is how it is".
The reason is NULLs in a relational table is fundamentally flawed since
logically, NULLs are not values and they have no type. ( Since they are not
typed values, and operations are applicable only to typed values, by
definition, NULLs cannot be in any operations. ) Due to this and certain
other reasons, relational model absolutely rejects anything that has to do
with NULLs because it is illogical.
However, SQL considers them as markers for representing the lack of a value,
but implements them as values in a table. In other words, in a table or
tabular expression, NULLs assume the type of the column's declared type and
associates itself with the operators of the type. Therefore, every SQL
implementation has a vague concept of "typed NULLs". Thus NULLs in an
integer column will be evaluated with respect to integer operators, NULLs in
a character column will be evaluated in character operations and so forth.
There are several inconsistencies related to NULLs, some of them very
subtle. When you use an operator whose operands are two distinctly typed
values, the evaluation of NULLs become suspect and arbitrary. It becomes
more ambiguous when NULLs are used in scalar expressions where operands are
not explicitly declared.
In SQL Server, the answer lies with how ISNULL treats null-able expressions.
SELECT NULL
SELECT RIGHT( NULL, 5 )
SELECT RIGHT(CONVERT(VARCHAR, NULL), 5)
SELECT ISNULL( NULL, 'Result if null')
SELECT ISNULL( RIGHT( NULL, 5 ), 'Result if null')
SELECT ISNULL( RIGHT(CONVERT(VARCHAR, NULL), 5), 'Result if null')
SELECT COALESCE( NULL, 'Result if null')
SELECT COALESCE( RIGHT( NULL, 5 ), 'Result if null')
SELECT COALESCE( RIGHT(CONVERT(VARCHAR, NULL), 5), 'Result if null')
You might also want to look at the distinction between ISNULL and COALESCE
at: www.aspfaq.com/2532
Anith

Thursday, February 16, 2012

Bring Data into SQL Server

I have the following tables on a non-SQL database that I can access
via ODBC:

Updated
OrderHeader
OrderDetails
InvoiceHeader
InvoiceDetails

When an order or an invoice is added/updated a record with the order
number is added to the Updated table. I need to loop through the
Updated table and for each record bring the data over to the
corresponding tables on the SQL server.

Does anyone have any ideas how to do this? I was attempting to do this
with a DTS job, but I don't know how to pass the order number to each
update and then loop and get the next order.

Any help would be appriciated. Let me know if you need any more
information.

Thanks,
MikeYou have also posted this individually to the .dts NG. please see my answer
there.

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know

"Mike" <mbaith@.yahoo.com> wrote in message
news:97741d04.0407201445.43a1d1b6@.posting.google.c om...
> I have the following tables on a non-SQL database that I can access
> via ODBC:
> Updated
> OrderHeader
> OrderDetails
> InvoiceHeader
> InvoiceDetails
> When an order or an invoice is added/updated a record with the order
> number is added to the Updated table. I need to loop through the
> Updated table and for each record bring the data over to the
> corresponding tables on the SQL server.
> Does anyone have any ideas how to do this? I was attempting to do this
> with a DTS job, but I don't know how to pass the order number to each
> update and then loop and get the next order.
> Any help would be appriciated. Let me know if you need any more
> information.
> Thanks,
> Mike

Tuesday, February 14, 2012

Break on Running Total

I am trying to create Packing List(s) based on an individual sales order.

Each Packing List page must be based upon the number of square feet.

I have set up a detail line with
Pieces, Width, Length and a running total of square feet (Pieces*width*length)

When the Running Total Square Feet > 400 then I need to go to a new page and reset the Running Total Square Feet and continue to print the remaining detail, until it again reaches 400 square feet.

I'm close, but I am having trouble. Can anyone help?

Note: Its MAS 90, if that makes a difference.What did you try and what problem are you facing?

Sunday, February 12, 2012

brain teaser - stagger the order of the results

This one has been stumping me for several days. I can run a query that
returns several different items from several different manufacturers,
each with a ranking score. Each manufacturer can have any number of
items:

Item_Name Manufacturer rank
Item 1 Manu_A 82
Item 2 Manu_A 65
Item 3 Manu_A 41
Item 4 Manu_B 32
Item 5 Manu_C 21
Item 6 Manu_B 19

However, I would like the records to be ordered so that the highest
ranking item is shown first, then the next highest item from a
different manufacturer is shown second, then the next highest item from
a third manufacturer is show, etc.:

Item 1 Manu_A 82
Item 4 Manu_B 32
Item 5 Manu_C 21
Item 2 Manu_A 65
Item 6 Manu_B 19
Item 3 Manu_A 41

Does anyone have any thoughts on how to order the results in this
fashion?

thanks,

Matt WeinerIt would be useful to see how you compute the Rank value. Perhaps your
result is possible by adapting your existing query. From what you've
given us, try this:

SELECT T1.item_name, T1.manufacturer, T1.rank
FROM (/* Your query */) AS T1
JOIN (/* Your query */) AS T2
ON T1.manufacturer = T2.manufacturer
AND T1.rank <= T2.rank
GROUP BY T1.item_name, T1.manufacturer, T1.rank
ORDER BY COUNT(*), T1.rank DESC

Just substitute your query or a view that contains it after the FROM
and JOIN.

--
David Portas
SQL Server MVP
--|||thanks. It works great. I appreciate the help.

Matt

Friday, February 10, 2012

Boots Performance

Hi ,
I already create clustered and non clustered index in order to improve the
reports performance. But after I test several times on my reports , the
processing time almost the same as before I index the table.
Any other method to increase the performance ? Can I index the "view" I
created ?
Travis Tan
Travis,
The group will need substantially more information in order to help diagnose
your performance issue. The basic answers to your questions are Yes. and
most likely yes depending on the version you are running.
Please post more information including:
SQL Server version
Basic hardware configuration
The query
The estimated query plan
What is the database used for (OLTP, DSS, Reporting, etc.)
"Travis" <Travis@.discussions.microsoft.com> wrote in message
news:5A01556F-70F4-4CC4-9779-2CAB8D4710F4@.microsoft.com...
> Hi ,
> I already create clustered and non clustered index in order to improve
> the
> reports performance. But after I test several times on my reports , the
> processing time almost the same as before I index the table.
> Any other method to increase the performance ? Can I index the "view" I
> created ?
>
> --
> Travis Tan

Boots Performance

Hi ,
I already create clustered and non clustered index in order to improve the
reports performance. But after I test several times on my reports , the
processing time almost the same as before I index the table.
Any other method to increase the performance ? Can I index the "view" I
created ?
Travis TanTravis,
The group will need substantially more information in order to help diagnose
your performance issue. The basic answers to your questions are Yes. and
most likely yes depending on the version you are running.
Please post more information including:
SQL Server version
Basic hardware configuration
The query
The estimated query plan
What is the database used for (OLTP, DSS, Reporting, etc.)
"Travis" <Travis@.discussions.microsoft.com> wrote in message
news:5A01556F-70F4-4CC4-9779-2CAB8D4710F4@.microsoft.com...
> Hi ,
> I already create clustered and non clustered index in order to improve
> the
> reports performance. But after I test several times on my reports , the
> processing time almost the same as before I index the table.
> Any other method to increase the performance ? Can I index the "view" I
> created ?
>
> --
> Travis Tan