• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Oracle dynamic sql

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #21
    Originally posted by suityou01 View Post
    Heeeeey. How am I the butt of the joke after what MS and LE posted?

    Edit : Don't forget to look closely
    You still think I'm wrong?

    You cannot use a variable name for a table directly.
    You have to build a sql string and execute that.

    Believe me.

    Comment


      #22
      Originally posted by mudskipper View Post
      You still think I'm wrong?

      You cannot use a variable name for a table directly.
      You have to build a sql string and execute that.

      Believe me.
      Or don't believe me - try it yourself.

      SqlServer:

      Code:
      create table suityTest (suityString varchar(20));
      insert into suityTest values ('value1')
      
      declare @tablename varchar(20) = 'suityTest';
      declare @value varchar(20) = 'value1';
      
      -- this will work
      select * from suityTest where suityString = @value;
      
      -- this will work
      declare @suitySQL varchar(max) = 
      'select * from ' + @tablename  +
      ' where suityString = ''' + @value +'''';
      exec (@suitySql)
      
      -- this will fail
      select * from @tablename where suityString = @value

      Comment


        #23
        MS, the article I linked to shows you to be wrong. Please read it.
        Knock first as I might be balancing my chakras.

        Comment


          #24
          Or to be fair you grasped the wrong end of the stick and started arguing the wrong point.
          Knock first as I might be balancing my chakras.

          Comment


            #25
            Originally posted by suityou01 View Post
            MS, the article I linked to shows you to be wrong. Please read it.
            Your article says:

            The string can also contain placeholders for bind arguments. However, you cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement.

            Comment


              #26
              Example uses the order date to build the name of the table that should contain the data, and then incorporates that name into an INSERT statement.

              Glad we are arguing the same point now.
              Knock first as I might be balancing my chakras.

              Comment


                #27
                Originally posted by mudskipper View Post
                Your article says:

                The string can also contain placeholders for bind arguments. However, you cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement.
                Can't see that quote anywhere in the article. Then again I am bouncing around in the back of a taxi at present.
                Knock first as I might be balancing my chakras.

                Comment


                  #28
                  Originally posted by suityou01 View Post
                  Can't see that quote anywhere in the article. Then again I am bouncing around in the back of a taxi at present.
                  I was quoting from your Oracle example.

                  Comment


                    #29
                    Originally posted by suityou01 View Post
                    Glad we are arguing the same point now.
                    Ah, you mean the section headed "B. Executing a dynamically built string"

                    Exactly which bit of what I said are you disagreeing with?

                    Comment


                      #30
                      Originally posted by mudskipper View Post
                      Ah, you mean the section headed "B. Executing a dynamically built string"

                      Exactly which bit of what I said are you disagreeing with?
                      The bit where you say you can't pass a bind var as a table name.

                      Why are you quoting from an oracle article to support you SQL server argument?
                      Knock first as I might be balancing my chakras.

                      Comment

                      Working...
                      X