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. General Programming
  3. C#
  4. Generate sql select statement from another select statement

Generate sql select statement from another select statement

Scheduled Pinned Locked Moved C#
helpquestiondatabase
14 Posts 3 Posters 0 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.
  • A AhmedMasum

    Suppose I got the following sql : select empno, empname, deptname,sal from emp, dept where emp.did= dept.did I need the following: If the column name is empno replace it by eno, If the table name is emp then replace it by employee, If the table is dept then replace it by department, if the column name is did replace it by deptid. That means after operation my the sql should be as follows: select eno, empname, deptname, sal from employee,department where employee.deptid=department.deptid How can I do that? Can I have any sample code for that??? Please help me. I am stuck on this place. I can't proceed without this.

    N Offline
    N Offline
    Not Active
    wrote on last edited by
    #2

    This is not a C# question. You should have asked in the General Database forum. What you are looking for are called aliases SELECT empno AS eno, emp AS employee, etc.


    only two letters away from being an asset

    A 1 Reply Last reply
    0
    • N Not Active

      This is not a C# question. You should have asked in the General Database forum. What you are looking for are called aliases SELECT empno AS eno, emp AS employee, etc.


      only two letters away from being an asset

      A Offline
      A Offline
      AhmedMasum
      wrote on last edited by
      #3

      I have to do it using c#. Because there is no direct interaction to database here. NO I don't want to alias the column name and table name. I have the replace/ create a new sql select statement by replacing the column names and table names with the new one (According to the condition's that I described above). Suppose I write an sql select statement in a text box. After button click I want to do the above replacement of column name and table name in the same text box...

      L N 2 Replies Last reply
      0
      • A AhmedMasum

        I have to do it using c#. Because there is no direct interaction to database here. NO I don't want to alias the column name and table name. I have the replace/ create a new sql select statement by replacing the column names and table names with the new one (According to the condition's that I described above). Suppose I write an sql select statement in a text box. After button click I want to do the above replacement of column name and table name in the same text box...

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #4

        so, use some of the methods in the string class; what is holding you up? :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


        A 1 Reply Last reply
        0
        • A AhmedMasum

          I have to do it using c#. Because there is no direct interaction to database here. NO I don't want to alias the column name and table name. I have the replace/ create a new sql select statement by replacing the column names and table names with the new one (According to the condition's that I described above). Suppose I write an sql select statement in a text box. After button click I want to do the above replacement of column name and table name in the same text box...

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #5

          dokhinahaoa wrote:

          That means after operation my the sql should be as follows: select eno, empname, deptname, sal from employee,department where employee.deptid=department.deptid

          dokhinahaoa wrote:

          I have to do it using c#.

          dokhinahaoa wrote:

          I have the replace/ create a new sql select statement by...

          These statements contradict each other. What do you actually want?


          only two letters away from being an asset

          A 1 Reply Last reply
          0
          • L Luc Pattyn

            so, use some of the methods in the string class; what is holding you up? :)

            Luc Pattyn


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


            A Offline
            A Offline
            AhmedMasum
            wrote on last edited by
            #6

            Suppose I got emp as table but if I replace all the emp inthe sql by employee then empname is also converting to employeename which is becoming to wrong column name

            L 1 Reply Last reply
            0
            • A AhmedMasum

              Suppose I got emp as table but if I replace all the emp inthe sql by employee then empname is also converting to employeename which is becoming to wrong column name

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #7

              so you must replace words, not parts of words. That requires a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. :)

              Luc Pattyn


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


              A 1 Reply Last reply
              0
              • N Not Active

                dokhinahaoa wrote:

                That means after operation my the sql should be as follows: select eno, empname, deptname, sal from employee,department where employee.deptid=department.deptid

                dokhinahaoa wrote:

                I have to do it using c#.

                dokhinahaoa wrote:

                I have the replace/ create a new sql select statement by...

                These statements contradict each other. What do you actually want?


                only two letters away from being an asset

                A Offline
                A Offline
                AhmedMasum
                wrote on last edited by
                #8

                You can think the sql as a string here. Just the format of the string is like an sql select statement. Because i m not sending the sql to the database before formatting as i mentioned. And I have to do the formatting using c#.

                1 Reply Last reply
                0
                • L Luc Pattyn

                  so you must replace words, not parts of words. That requires a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. :)

                  Luc Pattyn


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                  A Offline
                  A Offline
                  AhmedMasum
                  wrote on last edited by
                  #9

                  so you must replace words, not parts of words. That requires a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. How can I replace the word if I can't find the words? Because see the following string: select empno,empname,deptname,sal from emp, dept where emp.did= dept.did see here empno,empname,deptname,sal is one word. Because there is no space here. Also there may be column alias.It will be more difficult if i use group by, order by, having clause. In that case it will be more difficult. Ok it is easy to find different column name and table name (Using a parser). But problem is how can I just replace the old table name to new table name and old column name to new column name. again the problem is: Suppose I got emp as table but if I replace all the emp by employee then empname is also converting to employeename which is becoming to wrong column name

                  L N 2 Replies Last reply
                  0
                  • A AhmedMasum

                    so you must replace words, not parts of words. That requires a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. How can I replace the word if I can't find the words? Because see the following string: select empno,empname,deptname,sal from emp, dept where emp.did= dept.did see here empno,empname,deptname,sal is one word. Because there is no space here. Also there may be column alias.It will be more difficult if i use group by, order by, having clause. In that case it will be more difficult. Ok it is easy to find different column name and table name (Using a parser). But problem is how can I just replace the old table name to new table name and old column name to new column name. again the problem is: Suppose I got emp as table but if I replace all the emp by employee then empname is also converting to employeename which is becoming to wrong column name

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #10

                    dokhinahaoa wrote:

                    see here empno,empname,deptname,sal is one word. Because there is no space here

                    Then seperate it by comma not space :rolleyes: From all of you're posts it's clear you really have no clue what you are doing. I would suggest you turn this project over to someone who does.


                    only two letters away from being an asset

                    1 Reply Last reply
                    0
                    • A AhmedMasum

                      so you must replace words, not parts of words. That requires a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. How can I replace the word if I can't find the words? Because see the following string: select empno,empname,deptname,sal from emp, dept where emp.did= dept.did see here empno,empname,deptname,sal is one word. Because there is no space here. Also there may be column alias.It will be more difficult if i use group by, order by, having clause. In that case it will be more difficult. Ok it is easy to find different column name and table name (Using a parser). But problem is how can I just replace the old table name to new table name and old column name to new column name. again the problem is: Suppose I got emp as table but if I replace all the emp by employee then empname is also converting to employeename which is becoming to wrong column name

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #11

                      dokhinahaoa wrote:

                      empno,empname,deptname,sal is one word

                      not in my world. as I said: a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. :)

                      Luc Pattyn


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                      A 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        dokhinahaoa wrote:

                        empno,empname,deptname,sal is one word

                        not in my world. as I said: a parser, something that chops your text (SQL or other) into words based on whitespace and/or delimiters. :)

                        Luc Pattyn


                        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                        Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                        A Offline
                        A Offline
                        AhmedMasum
                        wrote on last edited by
                        #12

                        I got some idea. But do you know any good parsers name where i can easily find out the column names, table names, join tables names columns in join condition, column in where clause, column in group by clause and having clause. Also I can Replace the tables and columns names accordingly using the parser.

                        L 1 Reply Last reply
                        0
                        • A AhmedMasum

                          I got some idea. But do you know any good parsers name where i can easily find out the column names, table names, join tables names columns in join condition, column in where clause, column in group by clause and having clause. Also I can Replace the tables and columns names accordingly using the parser.

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #13

                          dokhinahaoa wrote:

                          do you know any good parsers name

                          :confused: I don't name the parsers I create; all it takes is some ten lines of code: scan the string for begin and end of identifier, then look it up in a replacement dictionary.

                          Luc Pattyn


                          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                          Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                          A 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            dokhinahaoa wrote:

                            do you know any good parsers name

                            :confused: I don't name the parsers I create; all it takes is some ten lines of code: scan the string for begin and end of identifier, then look it up in a replacement dictionary.

                            Luc Pattyn


                            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                            Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.


                            A Offline
                            A Offline
                            AhmedMasum
                            wrote on last edited by
                            #14

                            OOPs sorry... Can you share your parser code an how to use it?? I will be grateful to you...

                            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