|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is it posssible by relational database? FireBird?
I have table with lot of columns a1, a2,... etc. and I have to
get the following result set (each select is returning only one row): select cast('a1' as vachar(20)), a1 from my_table where id=5; select cast('a2' as vachar(20)), a2 from my_table where id=5; ... so: the table has the structure: id a1 a2 ... 1 10 11 ... 5 15 -40 ... and the resulting set for id=5 should go in form: 'a1' 15 'a2' -40 ... I am thinking about the following select-type SP create procedure ... returns (name varchar(20), res integer) as begin for some select from RDB$ table into i do begin select cast('get_field_name_by_position_in_table_definition(i)' as vachar(20)), get_field_value_by_position_in_table_definition(i) from my_table into :name, :res; suspend; end end but - is there some way how to simulate get_field_value... or get_field_name... for use in select? As far as I know - in PL/SQL it can be solved simply - because it allows to put field name in select during the execution of procedure - but - is it posiible for FB? Does some hackery using RDB$... tables exists to accomplish this idea? Or should ar fully redesign my_table? Last edited by egidy : November 9th, 2005 at 10:33 AM. |
|
#2
|
||||
|
||||
|
Quote:
You can use the following SQL to display the fields of a given TABLE: Code:
SELECT B.RDB$FIELD_NAME FROM RDB$RELATIONS A INNER JOIN RDB$RELATION_FIELDS B ON A.RDB$RELATION_NAME = B.RDB$RELATION_NAME WHERE A.RDB$RELATION_NAME=:TABLE // ORDER BY 1 --ordered by the field name or not Code:
SELECT B.RDB$FIELD_NAME AS FIELD FROM RDB$RELATIONS A INNER JOIN RDB$RELATION_FIELDS B ON A.RDB$RELATION_NAME = B.RDB$RELATION_NAME JOIN RDB$FIELDS C ON C.RDB$FIELD_NAME=B.RDB$FIELD_SOURCE WHERE A.RDB$RELATION_NAME=:TABLE AND C.RDB$COMPUTED_SOURCE IS NULL //ORDER BY 1 At the time I needed this, further processing of data was required so the fields and their values were displayed in 2 TListBoxes (Delphi) ... and the values were extracted with a different sql. Anyway, hope this helps and good luck.
__________________
If i've been helpful, please add to my reputation. My unfinished site: http://www.dever.ro |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Is it posssible by relatioal database? FireBird? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|