Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2005, 10:26 AM
egidy egidy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 166 egidy User rank is Private First Class (20 - 50 Reputation Level)egidy User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 15 h 49 m 31 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old November 11th, 2005, 03:35 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 5
Send a message via Yahoo to SilverDB
Lightbulb

Quote:
Originally Posted by egidy
...
'a1' 15
'a2' -40
...

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
this returns the computed fields also, so if you do not need the computed fields use this one instead:
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Is it posssible by relatioal database? FireBird?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT