Re: Sorting information using query analyser

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 08/10/04

  • Next message: Bruce H: "Update query analyzer grid results?"
    Date: Tue, 10 Aug 2004 18:24:21 +0200
    
    

    On Tue, 10 Aug 2004 08:43:02 -0700, Chris Scott wrote:

    >Hi all,
    >
    >I am trying to sort a really large file of information
    >and I need some help as I cant work out how to get some
    >of it.
    >the fields I have are:
    >csbytes
    >cscookie
    >csuriquery
    >I need to program to get:

    Hi Chris,

    Allow me to put you straigh on some terminology first. If you use an RDBMS
    like SQL Server, you don't have files, fields, records or programs, but
    you have tables, columns, rows and queries, stored procedures and/or
    triggers. You might say that thesse are only terms, but they're not. They
    relate to completely different concepts. A program tells a computer how to
    do something, step by step - a query tells the RDBMS what results you
    want; the RDBMS will figure out how to do it. A file is an ORDERED
    collection of records - a table is an UNordered colledtion of rows. A
    field usually refers to some consecutive bytes in a record that may
    contain any kind of data with any meaning - a row comes with a pre-set
    domain that all values must adhere to. Etc.

    You must change your mindset if you switch to using an RDBMS.

    >A list of the distinct values in cs bytes ( got have done
    >this one using: SELECT DISTINCT (csbytes) FROM
    >*filename*). However the list doesnt work properly as
    >when i use ORDER BY I get 0, 10000, 1001, etc so if
    >anyone knows how to order by the length of the field and
    >then in ascending order that would be REALLY useful.

    I guess it would, but wouldn't it even be more useful if you knew how to
    order by the numeric equivalent of csbytes?

    (a) useful
      SELECT DISTINCT csbytes
      FROM MyTable
      ORDER BY LEN(csbytes), csbytes

    (b) more useful
      SELECT DISTINCT csbytes
      FROM MyTable
      ORDER BY CAST (csbytes AS integer)

    Note: these queries use proprietary syntax. The official ANSI standard
    doesn't allow expressions in the ORDER BY list. SQL Server does allow this
    kind of queries, but other products may disallow this.

    >A count for the number of times each of these distinct
    >values appear in the csbytes list.

      SELECT csbytes, COUNT(*)
      FROM MyTable
      GROUP BY csbytes

    >A list of the first 100 longest values in cscookie.

      SELECT TOP 100 cscookie
      FROM MyTable
      ORDER BY LEN(cscookie) DESC

    See the above note about the ORDER BY clause. The TOP clause is a SQL
    Server specific extension to the SQL language as well.

    >A lost of the first 100 longest values in csuriquery.

    Same idea as above.

    >I also need to be able to compare cscookie and csuriquery
    >with a list of characters and find out if any of them
    >have characters that are not in the list I have, and to
    >display a boolean false if that is the case.

    There is no such thing as a boolean datatype in SQL. You're probably
    better off returning a text (e.g. "Not in list").

    Before I can help you with this query, I need to know the table structure
    of both tables involved. Please post DDL (CREATE TABLE statements,
    including all constraints - you may omit irrelevant columns). Post sample
    data (in the form of INSERT statements that I can cut and paste for
    testing) and expected output as well, to decrease the chance of
    misinterpretation.

    >If anyone can help me on any of these I would really
    >appreciate it as I am totally stuck and can't find what I
    >need online or in the SQL book I have.

    Maybe you should get a better book then - some of the questions you ask
    are pretty basic and should be covered in any decent SQL book. By the way,
    do you know that SQL Server comes with an extensive online reference? Try
    clicking Start / Program Files / Microsoft SQL Server / Books Online.

    Best, Hugo

    -- 
    (Remove _NO_ and _SPAM_ to get my e-mail address)
    

  • Next message: Bruce H: "Update query analyzer grid results?"

    Relevant Pages

    • Re: Unable to Apply SP4 to SQL 2000 Cluster (new Node)
      ... Rebuild the node in the failover cluster. ... Scenario 1" in SQL Server 2000 Books Online. ... This setup process updates to SP4 only the binaries on the new ...
      (microsoft.public.sqlserver.clustering)
    • Re: WSS 3.0 question
      ... I followed the advise given in removing WSS 3.0 etc, ... the server is complaining that the SQL service(?) was tempered with or corrupt. ... I may just instal the SQL server as I was going eventuall use it anyway. ... If WSUS 3.0 is installed, I would suggest you uninstall it and then you install WSS 3.0. ...
      (microsoft.public.windows.server.sbs)
    • Re: SQL Server 2005 Cluster Setup Quiz
      ... I did test and it did not install the client tools. ... http://www.clusterhelp.com - Cluster Training ... Microsoft SQL Server MVP ... Provide a template on how to read SQL Server 2005 setup log files. ...
      (microsoft.public.sqlserver.clustering)
    • Re: WSUS
      ... I'm not seeing performance issues with the full enchilada installed, and 25 users busy hitting SQL. ... WSUS isn't difficult to uninstall - if you have WSUS v2 (installed with SBS R2) uninstall R2 from add/remove programs. ... How can anyone work with 4 instances of SQL Server on the same box? ...
      (microsoft.public.windows.server.sbs)
    • Re: Cannot setup SQL Mail on SBS 2003
      ... Microsoft CSS Online Newsgroup Support ... Cannot setup SQL Mail on SBS 2003 ... The account you use to start the SQL Server service must be a domain ...
      (microsoft.public.windows.server.sbs)