Professional Web Applications Themes

How can i rewrite this? - Microsoft SQL / MS SQL Server

I don't think this q is searchgable (or what the hell is written ;-) ) SELECT TOP 5 * FROM T1 WHERE Col1 = 'mickey' AND CAST(SUBSTRING(Col2,6,1) AS INT) & 32 > 0 Is it the best way i can write this? any help appreciated regards -- == fabriZio...

  1. #1

    Default How can i rewrite this?

    I don't think this q is searchgable (or what the hell is written ;-) )

    SELECT
    TOP 5 *
    FROM
    T1
    WHERE
    Col1 = 'mickey'
    AND
    CAST(SUBSTRING(Col2,6,1) AS INT) & 32 > 0

    Is it the best way i can write this?

    any help appreciated

    regards

    --
    ==
    fabriZio




    fabriZio Guest

  2. #2

    Default Re: How can i rewrite this?

    What results are you trying to get?

    If there is an index on Col1 then it will use an index.

    I don't personally like the format (if thats what you are asking), i prefer
    to write code like this...


    SELECT TOP 5 *
    FROM T1
    WHERE Col1 = 'mickey'
    AND CAST(SUBSTRING(Col2,6,1) AS INT) & 32 > 0

    More succinct.

    --
    Tony Rogerson
    SQL Server MVP
    http://www.sqlserverfaq.com?mbr=21
    (Create your own groups, Forum, FAQ's and a ton more)


    Tony Guest

  3. #3

    Default Re: How can i rewrite this?

    Sorry..I have to be more precise:

    I would like to know if this piece:

    =========================================
    AND CAST(SUBSTRING(Col2,6,1) AS INT) & 32 > 0
    =========================================

    can be rewritten (and if yes, why) according the fact that if a search is
    made
    on a column for example in this way:

    AND LEFT(Col3) = '123'

    isn't searchable like :

    AND Col3 = '123'

    Thx


    --
    ==
    fabriZio


    "Tony Rogerson" <eu.com> ha scritto nel messaggio
    news:phx.gbl... 
    prefer 


    fabriZio Guest

  4. #4

    Default Re: How can i rewrite this?

    Not sure exactly what you are after still.

    This expression is not valid because LEFT takes two parameters ->
    AND LEFT(Col3) = '123'

    This is valid.....

    AND Col3 = '123'


    =========================================
    AND CAST(SUBSTRING(Col2,6,1) AS INT) & 32 > 0
    =========================================

    The '&' is a bitwise AND, are you trying to get the 6th byte in Col2 and do
    a bitwise AND with 32????

    --
    Tony Rogerson
    SQL Server MVP
    http://www.sqlserverfaq.com?mbr=21
    (Create your own groups, Forum, FAQ's and a ton more)


    Tony Guest

Similar Threads

  1. #39840 [NEW]: rewrite a multidimensional array causes a bug?
    By wesborland at email dot it in forum PHP Bugs
    Replies: 1
    Last Post: December 15th, 09:32 AM
  2. How to Rewrite Subsquery to joins
    By shreelu in forum MySQL
    Replies: 16
    Last Post: September 9th, 12:36 PM
  3. HELP!!!!! need to know how to rewrite on acrobat reader
    By l33ch@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 9
    Last Post: April 7th, 01:44 PM
  4. Rewrite <img> and <a> tags.
    By Simon Fredriksson in forum PHP Development
    Replies: 1
    Last Post: July 25th, 06:03 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