Professional Web Applications Themes

Tricky order by problem - Microsoft SQL / MS SQL Server

Hello I have a slight problem, so i did a simple test that didnt work......... CREATE TABLE #Test ( a int, b int ) INSERT INTO #Test(a,b)VALUES(14,7) INSERT INTO #Test(a,b)VALUES(8,0) INSERT INTO #Test(a,b)VALUES(1,2) SELECT * FROM #Test ORDER BY a/b FROM #Test ORDER BY a/b DROP TABLE #Test and i get "Divide by zero error encountered." is there a way to bypass this? word "bypass" is as you can imagine a way to "just get this crap to work so i can take a break and play golf" lol........ /Lasse...

  1. #1

    Default Tricky order by problem

    Hello

    I have a slight problem, so i did a simple test that didnt work.........


    CREATE TABLE #Test
    (
    a int,
    b int
    )

    INSERT INTO #Test(a,b)VALUES(14,7)
    INSERT INTO #Test(a,b)VALUES(8,0)
    INSERT INTO #Test(a,b)VALUES(1,2)

    SELECT * FROM #Test ORDER BY a/b FROM #Test ORDER BY a/b

    DROP TABLE #Test


    and i get "Divide by zero error encountered." is there a way to bypass this?
    word "bypass" is as you can imagine a way to "just get this crap to work so
    i can take a break and play golf" lol........

    /Lasse



    Lasse Guest

  2. #2

    Default Re: Tricky order by problem


    "Lasse Edsvik" <com> wrote in message
    news:%phx.gbl... 

    Something like

    SELECT * FROM #Test ORDER BY case when b = 0 then 0 else a/b end


    David


    David Guest

  3. #3

    Default Re: Tricky order by problem

    Try:

    SELECT * FROM #Test ORDER BY case when b = 0 then 0 else a/b end


    --
    Tom

    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinnaclepublishing.com/sql
    ..
    "Lasse Edsvik" <com> wrote in message news:%phx.gbl...
    Hello

    I have a slight problem, so i did a simple test that didnt work.........


    CREATE TABLE #Test
    (
    a int,
    b int
    )

    INSERT INTO #Test(a,b)VALUES(14,7)
    INSERT INTO #Test(a,b)VALUES(8,0)
    INSERT INTO #Test(a,b)VALUES(1,2)

    SELECT * FROM #Test ORDER BY a/b FROM #Test ORDER BY a/b

    DROP TABLE #Test


    and i get "Divide by zero error encountered." is there a way to bypass this?
    word "bypass" is as you can imagine a way to "just get this crap to work so
    i can take a break and play golf" lol........

    /Lasse



    Tom Guest

Similar Threads

  1. A tricky query problem
    By quiero mas in forum Coldfusion Database Access
    Replies: 2
    Last Post: November 12th, 07:17 AM
  2. Tricky problem with classes!
    By Lars Plessmann in forum PHP Development
    Replies: 13
    Last Post: May 15th, 12:08 PM
  3. tricky disable button problem
    By sid vishus in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: March 4th, 07:58 PM
  4. a tricky duplicates problem
    By Christoph in forum FileMaker
    Replies: 2
    Last Post: February 22nd, 07:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139