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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 24th, 2011, 04:16 AM
nagysz nagysz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 200 nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 19 m 28 sec
Reputation Power: 13
Variable substitution

hi,

i'll write an example to demonstrate what i want, and then i'll ask a question

there in an SP with output fields o1, o2, ... o15

i return an excel like table with this SP, the number of colums is unknown (but in the SP i limit it to 15)

there will be numbers in these cells, and the last column will be a TOTAL column

in the SP i calculate the ROWTOTAL variable


and then

Code:
if (max_col=1) then c2=rowtotal
else if (max_col=2) then c3=rowtotal
...
else if (max_col)=14 then c15=rowtotal



(max_col is the number of effective columns...the rest till 15 will not be used at listing)

and here's the question:

i'd like to replace this long if-else block with something more elegant

i thought of something like this:


Code:

-- say max_col=6, and rowtotal=123456

a=max_col+1;  -- then a=7
totalcol = 'o' || cast(a as varchar(3);  -- then totalcol='o7'
sql='totalcol =' || cast(rowtotal as varchar(20))  -- so sql = 'o7 = 123456';

execute statement sql;





this looks simple, but is not correct, since execute statement can only execute SQL statements like SELECT or EXECUTE PROCEDURE.

How should i do it correctly?


Thank you.

Last edited by nagysz : November 24th, 2011 at 04:23 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Variable substitution

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap