Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. SQL Server Query

SQL Server Query

Scheduled Pinned Locked Moved Clever Code
databasequestionsql-serversysadminhelp
26 Posts 10 Posters 27 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Carmichael
    wrote on last edited by
    #1

    Not exactly a subtle bug, but, perhaps a bug in SQLServer... I am trying to track down usage of a table before making changes to the application to ensure I don't break anything else. To find all of the stored procedures that use the table in question, I use the following query: SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier_price%' order by 1 The query returns a number of stored procedures, but at least two of them to not have the text 'supplier_price' in them; what they have is 'supplier price'. So... is this a bug in SQLServer, or am I querying incorrectly? Tim

    R R P C 4 Replies Last reply
    0
    • T Tim Carmichael

      Not exactly a subtle bug, but, perhaps a bug in SQLServer... I am trying to track down usage of a table before making changes to the application to ensure I don't break anything else. To find all of the stored procedures that use the table in question, I use the following query: SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier_price%' order by 1 The query returns a number of stored procedures, but at least two of them to not have the text 'supplier_price' in them; what they have is 'supplier price'. So... is this a bug in SQLServer, or am I querying incorrectly? Tim

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #2

      Why are you not using sp_depends[^]?


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

      T 2 Replies Last reply
      0
      • T Tim Carmichael

        Not exactly a subtle bug, but, perhaps a bug in SQLServer... I am trying to track down usage of a table before making changes to the application to ensure I don't break anything else. To find all of the stored procedures that use the table in question, I use the following query: SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier_price%' order by 1 The query returns a number of stored procedures, but at least two of them to not have the text 'supplier_price' in them; what they have is 'supplier price'. So... is this a bug in SQLServer, or am I querying incorrectly? Tim

        R Offline
        R Offline
        Rob Graham
        wrote on last edited by
        #3

        The underscore character is also a wildcard that matches any single character in a "like" query. So it's you... try SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier!_price%' order by 1 ESCAPE '!'

        T C 2 Replies Last reply
        0
        • R Rama Krishna Vavilala

          Why are you not using sp_depends[^]?


          Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

          T Offline
          T Offline
          Tim Carmichael
          wrote on last edited by
          #4

          Rama Krishna Vavilala wrote:

          Why are you not using sp_depends

          Because I didn't know about it until now... thank you! :-D

          J 1 Reply Last reply
          0
          • R Rob Graham

            The underscore character is also a wildcard that matches any single character in a "like" query. So it's you... try SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier!_price%' order by 1 ESCAPE '!'

            T Offline
            T Offline
            Tim Carmichael
            wrote on last edited by
            #5

            Thank you... I have to regularly switch between SQLServer, Oracle, Ingres, and a third party product, and don't necessary remember all of the nuances of each... Every day we learn something new, we are the richer for it...

            J 1 Reply Last reply
            0
            • T Tim Carmichael

              Not exactly a subtle bug, but, perhaps a bug in SQLServer... I am trying to track down usage of a table before making changes to the application to ensure I don't break anything else. To find all of the stored procedures that use the table in question, I use the following query: SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier_price%' order by 1 The query returns a number of stored procedures, but at least two of them to not have the text 'supplier_price' in them; what they have is 'supplier price'. So... is this a bug in SQLServer, or am I querying incorrectly? Tim

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Subtle Bugs is a forum to post examples of interesting, aggravating and subtle bugs that you've found and fixed. Do not post programming questions in this forum. This forum is purely for amusement and discussions and all actual programming questions will be removed.

              T R 2 Replies Last reply
              0
              • P PIEBALDconsult

                Subtle Bugs is a forum to post examples of interesting, aggravating and subtle bugs that you've found and fixed. Do not post programming questions in this forum. This forum is purely for amusement and discussions and all actual programming questions will be removed.

                T Offline
                T Offline
                Tim Carmichael
                wrote on last edited by
                #7

                Well, since I perceived this as a bug in SQLServer, wrongly it seems... it seemed appropriate to post it here. From the header for the area: post the bugs you've found It was not intended as a programming question, merely an informative message. If the powers-that-be do not like the message, they can remove it. Tim

                P 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Subtle Bugs is a forum to post examples of interesting, aggravating and subtle bugs that you've found and fixed. Do not post programming questions in this forum. This forum is purely for amusement and discussions and all actual programming questions will be removed.

                  R Offline
                  R Offline
                  Rama Krishna Vavilala
                  wrote on last edited by
                  #8

                  Actually, it is a subtle bug, see Rob's reply.


                  Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                  G 1 Reply Last reply
                  0
                  • T Tim Carmichael

                    Well, since I perceived this as a bug in SQLServer, wrongly it seems... it seemed appropriate to post it here. From the header for the area: post the bugs you've found It was not intended as a programming question, merely an informative message. If the powers-that-be do not like the message, they can remove it. Tim

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #9

                    But and fixed is in bold. You hadn't fixed the bug, you didn't even know the bug was your fault, you thought it was in SQL, you were looking for (and received) help solving the problem. Now that you have the solution you should post it.

                    T R 2 Replies Last reply
                    0
                    • P PIEBALDconsult

                      But and fixed is in bold. You hadn't fixed the bug, you didn't even know the bug was your fault, you thought it was in SQL, you were looking for (and received) help solving the problem. Now that you have the solution you should post it.

                      T Offline
                      T Offline
                      Tim Carmichael
                      wrote on last edited by
                      #10

                      And if anyone is reading this thread, they have a partial solution... To quote myself: if the powers-that-be do not like the message, they can remove it.

                      1 Reply Last reply
                      0
                      • R Rama Krishna Vavilala

                        Actually, it is a subtle bug, see Rob's reply.


                        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                        G Offline
                        G Offline
                        Guffa
                        wrote on last edited by
                        #11

                        I don't think that it's very subtle. I knew what the bug was before I even looked at the code in the post. Using underscore as a wild card character is not very well hidden in the documentation either. Wherever you look up the like operator in MSDN, it's mentioned. If one looked up that percent can be used as a wildcard, it would be hard to miss the other wildcard character.

                        --- b { font-weight: normal; }

                        P T 2 Replies Last reply
                        0
                        • P PIEBALDconsult

                          But and fixed is in bold. You hadn't fixed the bug, you didn't even know the bug was your fault, you thought it was in SQL, you were looking for (and received) help solving the problem. Now that you have the solution you should post it.

                          R Offline
                          R Offline
                          Rob Graham
                          wrote on last edited by
                          #12

                          It was a team effort. Tim supplied the bug, I supplied a fix. ;P

                          1 Reply Last reply
                          0
                          • G Guffa

                            I don't think that it's very subtle. I knew what the bug was before I even looked at the code in the post. Using underscore as a wild card character is not very well hidden in the documentation either. Wherever you look up the like operator in MSDN, it's mentioned. If one looked up that percent can be used as a wildcard, it would be hard to miss the other wildcard character.

                            --- b { font-weight: normal; }

                            P Offline
                            P Offline
                            Prakash Nadar
                            wrote on last edited by
                            #13

                            Guffa wrote:

                            Using underscore as a wild card character is not very well hidden in the documentation either. Wherever you look up the like operator in MSDN, it's mentioned. If one looked up that percent can be used as a wildcard, it would be hard to miss the other wildcard character.

                            you explained why its subtle. :)


                            -Prakash

                            G 1 Reply Last reply
                            0
                            • R Rama Krishna Vavilala

                              Why are you not using sp_depends[^]?


                              Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

                              T Offline
                              T Offline
                              Tim Carmichael
                              wrote on last edited by
                              #14

                              Another reason I can't use sp_depends, is that there are a number of stored procedures that build query strings dynamically or having them otherwise wrapped in an 'EXEC' statement. Will sp_depends find instances of tables so enclosed? Besides stored procedures, I also need to search jobs (understanding that the tables will be different); the search problem would be the same.

                              1 Reply Last reply
                              0
                              • G Guffa

                                I don't think that it's very subtle. I knew what the bug was before I even looked at the code in the post. Using underscore as a wild card character is not very well hidden in the documentation either. Wherever you look up the like operator in MSDN, it's mentioned. If one looked up that percent can be used as a wildcard, it would be hard to miss the other wildcard character.

                                --- b { font-weight: normal; }

                                T Offline
                                T Offline
                                Tim Carmichael
                                wrote on last edited by
                                #15

                                If you read the rest of my posts, you would see that I regulary have to switch between multiple database systems. Of these systems, using a '%' character as a multi-character wildcard seems to be common, however, I am used to using a '?' character as a single character wildcard. Hence the confusion on my part. Since we do not always read all documentation available, what was subtle to one may be glaringly obvious to others.

                                G 1 Reply Last reply
                                0
                                • R Rob Graham

                                  The underscore character is also a wildcard that matches any single character in a "like" query. So it's you... try SELECT o.name, c.number, c.text FROM sysobjects AS o INNER JOIN syscomments AS c ON o.id = c.id WHERE (o.xtype = 'P') and c.text like '%supplier!_price%' order by 1 ESCAPE '!'

                                  C Offline
                                  C Offline
                                  Chris Losinger
                                  wrote on last edited by
                                  #16

                                  Rob Graham wrote:

                                  The underscore character is also a wildcard

                                  :wtf: that's just plain fncked up.

                                  image processing | blogging

                                  R 1 Reply Last reply
                                  0
                                  • P Prakash Nadar

                                    Guffa wrote:

                                    Using underscore as a wild card character is not very well hidden in the documentation either. Wherever you look up the like operator in MSDN, it's mentioned. If one looked up that percent can be used as a wildcard, it would be hard to miss the other wildcard character.

                                    you explained why its subtle. :)


                                    -Prakash

                                    G Offline
                                    G Offline
                                    Guffa
                                    wrote on last edited by
                                    #17

                                    Mr.Prakash wrote:

                                    you explained why its subtle.

                                    So if the documentation clearly describes how something works, and you use it wrong anyway, it's subtle?

                                    --- b { font-weight: normal; }

                                    P 1 Reply Last reply
                                    0
                                    • T Tim Carmichael

                                      If you read the rest of my posts, you would see that I regulary have to switch between multiple database systems. Of these systems, using a '%' character as a multi-character wildcard seems to be common, however, I am used to using a '?' character as a single character wildcard. Hence the confusion on my part. Since we do not always read all documentation available, what was subtle to one may be glaringly obvious to others.

                                      G Offline
                                      G Offline
                                      Guffa
                                      wrote on last edited by
                                      #18

                                      I see. So when the code doesn't work the way you expect, what do you do? Do you think: "Hm... this command doesn't work the way that I expect, perhaps I should look it up in the documentation to see how it really works."? No. Of course not. As you can not possibly be wrong, the logical conclusion is of course that there is a bug in the database software. ;)

                                      --- b { font-weight: normal; }

                                      R 1 Reply Last reply
                                      0
                                      • G Guffa

                                        I see. So when the code doesn't work the way you expect, what do you do? Do you think: "Hm... this command doesn't work the way that I expect, perhaps I should look it up in the documentation to see how it really works."? No. Of course not. As you can not possibly be wrong, the logical conclusion is of course that there is a bug in the database software. ;)

                                        --- b { font-weight: normal; }

                                        R Offline
                                        R Offline
                                        Rob Graham
                                        wrote on last edited by
                                        #19

                                        Guffa,I think you're being a bit padantic here. In the original post, Tim did allow for it to be his error rather than a bug. I would argue that even if one did read the docs (and BOL is only marginally better than MSDN), given the context of the _, it would be very easy to overlook it's meaning, and be confused by the results. The "bug is just like if(x=1) instead of if(x==1), both are a case of overooking an "obvious" error because of the context of the error...:rose:

                                        G 1 Reply Last reply
                                        0
                                        • G Guffa

                                          Mr.Prakash wrote:

                                          you explained why its subtle.

                                          So if the documentation clearly describes how something works, and you use it wrong anyway, it's subtle?

                                          --- b { font-weight: normal; }

                                          P Offline
                                          P Offline
                                          Prakash Nadar
                                          wrote on last edited by
                                          #20

                                          no it was not the wrong usage, else it would have given compiler error or sql error. he missed the understanding of _ for a moment.


                                          -Prakash

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups