Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Alpha SQL select statement: replacing column name with argument

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

    Alpha SQL select statement: replacing column name with argument

    Hi,

    I have defined the following argument:

    DIM ARGS AS SQL::ARGUMENTS
    Args.add("QueActivo",e.datasubmitted.activo)

    Posible values for the argument "QueActivo" are: XAUEUR, XAUUSD, XAGEUR, XAGUSD.

    The table is as follows:
    [SPH_DATE] [XAUEUR] XAUUSD] XAGEUR] XAGUSD]

    and the SQL select statement should have 2 columns:
    sql = <<%txt%
    SELECT SPH_DATE,

    and the next column should be the result of the argument "QueActivo".
    %txt%

    My question is: In the select statement, can I replace the the column name with the content of the argument?


    Many thanks for your help,
    Javier

    #2
    Re: Alpha SQL select statement: replacing column name with argument

    SELECT sph_date, :QueActivo...

    connection.execute(select_statement, args)
    should do it
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    [email protected]
    Skype:[email protected]
    1 914 924 5171

    Comment


      #3
      Re: Alpha SQL select statement: replacing column name with argument

      Hi Govindan,
      thanks for coming back on this.

      If I follow your advise, I get the following result:

      ['25.04.2014', XAUEUR],
      ['28.04.2014', XAUEUR],
      ['29.04.2014', XAUEUR],
      ['30.04.2014', XAUEUR],
      ['01.05.2014', XAUEUR],
      ['02.05.2014', XAUEUR],
      ['05.05.2014', XAUEUR],
      ['06.05.2014', XAUEUR],
      ['07.05.2014', XAUEUR],

      since the argument called :QueActivo='XAUEUR'

      and what I would like to get is the content of the column called 'XAUEUR'. So It should show the content of the column called XAUEUR:

      ['25.04.2014', 992,32],
      ['28.04.2014', 991,21],
      ['29.04.2014', 884,31],
      ['30.04.2014', 892,32],
      ['01.05.2014', 839,43],
      ['02.05.2014', 999,32],
      ['05.05.2014', 983,32],
      ['06.05.2014', 903,23],
      ['07.05.2014', 943,09],



      Any idea?
      cheers,
      javier

      Comment


        #4
        Re: Alpha SQL select statement: replacing column name with argument

        we both are not following each other
        don't post part of your sql statement or the arguments list
        post full statement and full argument builder.

        edit: I deleted the code let me test it before I post it back.
        SELECT column1, column2 did not give you the answer?
        there is something you are doing, want to do I did not fully comprehend.
        if you explain further I can help.
        Last edited by GGandhi; 05-24-2014, 09:07 AM.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: Alpha SQL select statement: replacing column name with argument

          ok, below is the function with full statement and the argument list ( I use it to load the data in a google chart):
          I use a control to collect the activo1 variable and later this will be contained in the argument QueActivo1 . And this is the name of the column that I want to show.

          function newChartData as c (e as p)

          DIM ARGS AS SQL::ARGUMENTS
          Args.add("QueActivo1",e.datasubmitted.activo1)
          Args.add("QueFecha",Convert_type(e.datasubmitted.fecha_ini,"N"))

          dim sql as c
          sql = <<%txt%
          SELECT convert(varchar, SPH_DATE, 104) AS SPH_DATE_F,
          :QueActivo1 AS 'Acumulado1'
          FROM Retornos_PCT1
          WHERE sph_date>DATEADD(day, :QueFecha , GETDATE())
          ORDER BY SPH_DATE
          %txt%
          dim cn as sql::Connection
          cn.open("::Name::port_app_sql")
          dim flag as l
          flag = cn.Execute(sql,args)
          dim rs as sql::ResultSet
          rs = cn.ResultSet
          dim template as c
          template = "['{js_escape(ds.data(\"SPH_DATE_F\"))}', {ds.data(\"Acumulado1\")}, {ds.data(\"Acumulado2\")}],"
          dim template as c
          dim txt as c
          txt = a5_mergedataintotemplate(template,rs)
          txt = rtrim(txt,",")
          txt = "[['Fecha:', 'Retornos#1']," + txt + "]"
          dim js as c
          js = "{dialog.object}._data = " + txt + ";doChart1();"
          newChartData = js
          end function

          Comment


            #6
            Re: Alpha SQL select statement: replacing column name with argument

            function newChartData as c (e as p)

            DIM ARGS AS SQL::ARGUMENTS
            Args.add("QueActivo1",e.datasubmitted.activo1)
            Args.add("QueFecha",Convert_type(e.datasubmitted.fecha_ini,"N"))

            dim sql as c
            sql = <<%txt%
            SELECT convert(varchar, SPH_DATE, 104) AS SPH_DATE_F, the second_field_name FROM Retornos_PCT1
            WHERE sph_date>DATEADD(day, :QueFecha , GETDATE()) and (the second_field_name = :QueActivo1) ORDER BY SPH_DATE
            %txt%
            dim cn as sql::Connection
            cn.open("::Name::port_app_sql")
            dim flag as l
            flag = cn.Execute(sql,args)
            dim rs as sql::ResultSet
            rs = cn.ResultSet
            dim template as c
            template = "['{js_escape(ds.data(\"SPH_DATE_F\"))}', {ds.data(\"Acumulado1\")}, {ds.data(\"Acumulado2\")}],"
            dim template as c
            dim txt as c
            txt = a5_mergedataintotemplate(template,rs)
            txt = rtrim(txt,",")
            txt = "[['Fecha:', 'Retornos#1']," + txt + "]"
            dim js as c
            js = "{dialog.object}._data = " + txt + ";doChart1();"
            newChartData = js
            end function
            I don't think arguments will work in the select field area
            I made a change see if this works for you.
            I do not work with this type of charting etc., so my help will be limited.
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: Alpha SQL select statement: replacing column name with argument

              Thanks Govindan.
              I will try your sugestion.
              All the best,
              javier

              Comment


                #8
                Re: Alpha SQL select statement: replacing column name with argument

                When an argument is used, it is replaced by its value when run. In the case of a character argument, it is quoted. You can see what happens with this example
                Code:
                dim args as sql::Arguments
                args.set("Field1","Firstname")
                args.set("field2","Lastname")
                SQL = "select :Field1, :Field2 from Customer WHERE Lastname = :Field2"
                
                ?replace_arguments_in_string(SQL,args)
                = select "Firstname", "Lastname" from Customer WHERE Lastname = "Lastname"
                What you want to do is to replace the argument without quotes. The best way to do that is to build the query string before running the query.
                Code:
                Field1  = "Firstname"
                Field2 = "LastName"
                SQL = "SELECT "+field1+","+ field2+" FROM Customer"
                ?sql
                = "SELECT Firstname,LastName FROM Customer"
                If you are passing in arguments, you can still use then with a slight variation.
                Code:
                dim args as sql::Arguments
                args.set("Field1","Firstname")
                args.set("field2","Lastname")
                SQL = "SELECT "+args.find("Field1").data+","+ args.find("Field2").data+" FROM Customer"
                
                ?sql
                = "SELECT Firstname,Lastname FROM Customer"
                Of course, you would need to verify the arguments exist for that method to work

                Comment


                  #9
                  Re: Alpha SQL select statement: replacing column name with argument

                  Exactly what I was looking for!!!!
                  Many thanks Jerry.
                  Cheers,
                  Javier

                  Comment


                    #10
                    Re: Alpha SQL select statement: replacing column name with argument

                    Here's how I do it:

                    Code:
                    Dim SQL as c
                    Dim conn as SQL::connection
                    Dim args as SQL::Arguments
                    Dim rs as SQL::ResultSet
                    
                    vFields= <<%str%
                    Cust_Id
                    Company
                    Address1
                    Address2
                    Address3
                    City
                    State
                    Zip
                    Country
                    DT_Stamp
                    %str%
                    
                    vFields = crlf_to_comma(vFields)
                    SQL_Select = "SELECT " + vFields + " FROM customers"
                    
                    flag = conn.open("::Name::ABC123")
                    flag = conn.execute(SQL_Select, args)
                    rs = conn.ResultSet
                    conn.close()
                    Peter
                    AlphaBase Solutions, LLC

                    [email protected]
                    https://www.alphabasesolutions.com


                    Comment


                      #11
                      Re: Alpha SQL select statement: replacing column name with argument

                      Thanks Peter

                      Comment


                        #12
                        Re: Alpha SQL select statement: replacing column name with argument

                        Does anyone see why this does not work?
                        Code:
                        function check_digit_pitts as c (e as p)
                        	Dim cn as sql::connection 
                        Dim args as SQL::Arguments
                        
                        args.set("tablename",e.dataSubmitted.table_name)
                        
                        flag = cn.open("::Name::urbangrocery")
                        cn.BeginTransaction()
                        dim sqlCommand as c
                        sqlCommand = "select recordid, upc from" + args.find("tablename").data+"where upc <> '' and upc is not null and length(upc) = 13"
                        	
                        flag = cn.execute(sqlCommand,args)
                        The SQL error generated is
                        Database API specific error

                        Your database has returned the following error code and description to Alpha Five.
                        Consult your database documentation for further information.

                        1064 - 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'upc <> '' and upc is not null and length(upc) = 13' at line 1'
                        Richard Urban

                        Grocery Delivery Software for Stores and Entrepreneurs: http://www.urbangrocery.com

                        Comment


                          #13
                          Re: Alpha SQL select statement: replacing column name with argument

                          sqlCommand = "select recordid, upc from" + args.find("tablename").data+"where upc <> '' and upc is not null and length(upc) = 13"

                          flag = cn.execute(sqlCommand,args)
                          this form of sqlStatement is very advanced for me, however i am only thinking, if you provide the name of the table by args.find("tablename").data then there is only sqlStatment there is no argument for alpha to replace with.
                          on the other hand if your sqlStatment is
                          Code:
                          sqlCommand = "SELECT recordid, upc FROM :tableName WHERE upc <> '' AND upc IS NOT NULL AND length(upc) = 13"
                          args.set("tableName", e.dataSubmitted.tablename)	
                          flag = cn.execute(sqlCommand,args)
                          then alpha can replace the :tableName with the e.dataSubmitted.tablename
                          this is my opinion.
                          as i said this is too advanced for me to start with.
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          [email protected]
                          Skype:[email protected]
                          1 914 924 5171

                          Comment


                            #14
                            Re: Alpha SQL select statement: replacing column name with argument

                            Code:
                            sqlCommand = "select recordid, upc from" + args.find("tablename").data+"where upc <> '' and upc is not null and length(upc) = 13"
                            	
                            flag = cn.execute(sqlCommand)
                            Code:
                            sqlCommand = "select recordid, upc from" + e.dataSubmitted.tablename+"where upc <> '' and upc is not null and length(upc) = 13"
                            	
                            flag = cn.execute(sqlCommand)
                            are equal in my opinion, again.
                            thanks for reading

                            gandhi

                            version 11 3381 - 4096
                            mysql backend
                            http://www.alphawebprogramming.blogspot.com
                            [email protected]
                            Skype:[email protected]
                            1 914 924 5171

                            Comment


                              #15
                              Re: Alpha SQL select statement: replacing column name with argument

                              Put a space after from and another space prior to where between the quote so the word is separate from the variable.

                              Use debug(1), a messagebox, trace window, or write the sql to a log file to inspect what it looks like after the variable is inserted.

                              Code:
                              sqlCommand = "select recordid, upc from" + args.find("tablename").data+"where upc <> '' and upc is not null and length(upc) = 13"
                              
                              vs
                              
                              sqlCommand = "select recordid, upc from " + args.find("tablename").data+" where upc <> '' and upc is not null and length(upc) = 13"
                              Al Buchholz
                              Bookwood Systems, LTD
                              Weekly QReportBuilder Webinars Thursday 1 pm CST

                              Occam's Razor - KISS
                              Normalize till it hurts - De-normalize till it works.
                              Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                              When we triage a problem it is much easier to read sample systems than to read a mind.
                              "Make it as simple as possible, but not simpler."
                              Albert Einstein

                              http://www.iadn.com/images/media/iadn_member.png

                              Comment

                              Working...
                              X