|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
What do you mean loop through the result? How to loop through columns?
|
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
Quote:
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? |
|
#6
|
|||
|
|||
|
Quote:
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 |
|
#7
|
|||
|
|||
|
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...
|
|
#8
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Getting data from a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|