• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use * / Column in sql query

 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All

I have 5 column
1 Col = Code numeric [ 1,2,3 ]
2 Col = Name varchar [David, Anand, Peter ]
3 Col = Salary numeric [ 5000,6000,70000]
4 col = factor char [ * , * , / ]
5 Col = rate numeric [ 10,10,0.5]

How can I use column # 4 in SQL query. Please help.

i.e. select code,name,salary, (salary + factor + rate) as amount from salary_table . This query is not working


 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I understand it right that you want to use the operator stored in the factor column? It's not possible to do it directly - SQL doesn't evaluate expressions dynamically. The closest you can get probably is:

Hopefully your database supports the case expression, but even if it doesn't, it probably has an if function or a similar construct.

You'll need to hard code every possible operator into the query. It would be a good idea to put a check constraint on the factor column to only allow characters representing supported operators.
 
Anand Karia
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh Yah.... Sorry I forgot.

Thank you a lot Martin.
 
reply
    Bookmark Topic Watch Topic
  • New Topic