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 December 31st, 2007, 08:14 AM
KameS KameS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 4 KameS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
Getting data from a table

Hi
I have a following problem: I have a table that has fields named d01, d02, ..., d31, and i want to get data from them, but I need to do something like select d01 from ... where ..., and do stuff for each of these columns, and i have to repeat the exact same code 31 times. What I want to know is if there's a way for doing something like:
select columnByName('D01') from ..., and of course eventually place it in a loop, so it would look like this

i = 1;
while (i < 32) do begin
select columnbyname('d' || i) from...
....
i = i + 1;
end

Is there a way to do that in FireBird?

Reply With Quote
  #2  
Old December 31st, 2007, 01:54 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 857 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 11 h 14 m 52 sec
Reputation Power: 19
You need to get all the columns in one SELECT and then loop through the resulting values.

That has to be more efficient than 32 individual SELECT statements.

Clive

Reply With Quote
  #3  
Old January 3rd, 2008, 02:50 AM
KameS KameS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 4 KameS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
What do you mean loop through the result? How to loop through columns?

Reply With Quote
  #4  
Old January 6th, 2008, 04:03 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 857 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 11 h 14 m 52 sec
Reputation Power: 19
You SELECT the 32 columns into 32 variables then loop through the variables.
Are you talking about a Stored Procedure or a client side language?

Reply With Quote
  #5  
Old January 7th, 2008, 04:13 AM
KameS KameS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 4 KameS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
You SELECT the 32 columns into 32 variables then loop through the variables.
Are you talking about a Stored Procedure or a client side language?

I'm talking about a stored procedure. Didn't I mention that?
How do I loop through the variables? Is there a way to declare an array or something?

Reply With Quote
  #6  
Old January 7th, 2008, 05:57 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 857 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 11 h 14 m 52 sec
Reputation Power: 19
Quote:
Originally Posted by KameS
I'm talking about a stored procedure. Didn't I mention that?
How do I loop through the variables? Is there a way to declare an array or something?

I do not think so.
That rules out looping in an SP. (Others may have another solution)
You will have to declare 32 variables -

I may be out of line here but
If you have to do the same thing to 32 columns of a table, it looks to me as if
you have a schema design problem.
The 32 columns are probably better stored as 32 records in a normalized detail table.

If you can not change the schema, can you do the processing in a client application that will let you loop through the columns?

Clive

Reply With Quote
  #7  
Old January 8th, 2008, 05:08 AM
KameS KameS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 4 KameS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
It is a GREAT design problem, and I have no idea who thought of such a ridicullous design. But, alas, I cannot change it. And I do not think manipulating columns in the client code is a vary good solution either. Seems to me I'm stuck with a procedure that is few thousend lines of code long...

Reply With Quote
  #8  
Old January 8th, 2008, 10:50 AM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,850 LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level)LyonHaert User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 11 h 9 m 27 sec
Reputation Power: 524
You can concatenate together a query string within a sproc and then use a command to execute the contents of the string as an SQL statement. And this is the page that taught me. That would allow you to use a loop.
__________________
Joel B Fant
"An element of conflict in any discussion is a very good thing. Shows everybody's taking part, nobody left out. I like that."

.NET Must-Haves
Tools: Reflector
References: Threading in .NET

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Getting data from a table


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

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





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