Generate sql select statement from another select statement
-
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.
-
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.
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
-
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
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...
-
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...
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.
-
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...
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
-
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.
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
-
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
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.
-
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
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#.
-
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.
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
-
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
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
-
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
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.
-
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.
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.
-
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.
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.
-
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.
OOPs sorry... Can you share your parser code an how to use it?? I will be grateful to you...