Sunday, March 11, 2012
Bug in SELECT TOP (100) PERCENT with ORDER BY 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.
Tuesday, February 14, 2012
Breaking apart Column into rows
to turn into rows.
Example:
A column contains ROBERT%CAMARDA, I want to turn that into two rows,
one row with ROBERT and antoher row with CAMARDA.
I will have source rows that have zero, one, or many percent sign
delimiters that will correspond to that many rows (One percent sign
will create 2 rows, 2 percent signs will create 3 rows and so forth).
Any thoughts?
TIA
Robrcamarda (rcamarda@.cablespeed.com) writes:
> I have a column that has text delimited by a percent sign that I wish
> to turn into rows.
> Example:
> A column contains ROBERT%CAMARDA, I want to turn that into two rows,
> one row with ROBERT and antoher row with CAMARDA.
> I will have source rows that have zero, one, or many percent sign
> delimiters that will correspond to that many rows (One percent sign
> will create 2 rows, 2 percent signs will create 3 rows and so forth).
Have a look at an article on my web site:
http://www.sommarskog.se/arrays-in-sql.html.
Specifically, look at "List-of-strings" and "Unpacking a table column".
You did not say which version of SQL Server you are using. The article
is written for SQL 2000. SQL 2005 provides a new operator CROSS APPLY
which is good for the column bit. In SQL 2000, you will have to run
it row by row.
--
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
Breakdown database by percent
percent of win. For example:
lets say we have 100,000 rated players. I want to find the win the top 1%
of players contribute followed by
2%
3%
4%
.
.
100%
My fields are Player_ID, Win.
I need help writing a procdure to group/calculate this for me. The database
grows automatically so the procudre needs to automatically adjust based on
the growth.
ThanksI don't think I understand your question fully but on it's surface
it sounds like you can benefit from the TOP keyword in your
SELECT.
SELECT TOP n [PERCENT]
See BOL for more details
<brian.shannon@.diamondjo.com> wrote in message
news:OaRnZCgFFHA.2156@.TK2MSFTNGP09.phx.gbl...
> I am in the Casino industry and would like to break down our database by
> percent of win. For example:
> lets say we have 100,000 rated players. I want to find the win the top 1%
> of players contribute followed by
> 2%
> 3%
> 4%
> .
> .
> 100%
> My fields are Player_ID, Win.
> I need help writing a procdure to group/calculate this for me. The
database
> grows automatically so the procudre needs to automatically adjust based on
> the growth.
> Thanks
>|||>> I need help writing a procdure to group/calculate this for me.
Sure, it is easy, but many here won't have the inclination to create sample
tables, insert sample data & write up a query for you when you did not
bother to post required information for others to repro the problem. Read
www.aspfaq.com/5006 & provide table structures, sample data & expected
results so that others can suggest a tested solution.
Anith