ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion 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 May 16th, 2005, 08:24 AM
andy11983 andy11983 is offline
Newbie wannabe extrodanaire
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: stoke
Posts: 315 andy11983 User rank is Corporal (100 - 500 Reputation Level)andy11983 User rank is Corporal (100 - 500 Reputation Level)andy11983 User rank is Corporal (100 - 500 Reputation Level)andy11983 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 9 h 25 m 6 sec
Reputation Power: 6
declaring variables from within a query

Hi,

I was just wondering if it is possibly to set a variable from withina query.

e.g
<cfquery name ="somequery">
select name,age,phone from sometable

<cfset myvar1 = age>
</query>

I need the colum from this table to be set to that variable name so i can pass it through my documents.

Thanks

Andy

Reply With Quote
  #2  
Old May 16th, 2005, 08:40 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 25 m 11 sec
Reputation Power: 5
Quote:
Originally Posted by andy11983
e.g
<cfquery name ="somequery">
select name,age,phone from sometable

<cfset myvar1 = age>
</query>

I need the colum from this table to be set to that variable name so i can pass it through my documents.


I'm confused. Are you trying to set myvar1 to the column name age or the value of age?

<cfset myvar1 = "age">
or
<cfset myvar1 = query.age>

Reply With Quote
  #3  
Old May 16th, 2005, 09:06 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 42 m 54 sec
Reputation Power: 53
I'm with Bastion in that I'm not sure what you're trying to do. You can set the variable to the name of the column, or to the value of the column (after the query is finished).
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #4  
Old May 17th, 2005, 05:24 AM
Faunus Faunus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Location: Manchester, UK
Posts: 129 Faunus User rank is Sergeant (500 - 2000 Reputation Level)Faunus User rank is Sergeant (500 - 2000 Reputation Level)Faunus User rank is Sergeant (500 - 2000 Reputation Level)Faunus User rank is Sergeant (500 - 2000 Reputation Level)Faunus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 13 h 10 m 32 sec
Reputation Power: 10
I think what he means is, is the following possible: (?)

<cfquery name="myQuery" datasource="foo">
SELECT name, age, phone FROM myTable
<cfset myVar="#myQuery.age#">
</cfquery>

Edit: for typo fix

Reply With Quote
  #5  
Old May 17th, 2005, 08:25 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 42 m 54 sec
Reputation Power: 53
No, that's not possible because until the query is finished and returned from the database, there is no query named "myQuery".

Reply With Quote
  #6  
Old May 17th, 2005, 03:16 PM
mlearn mlearn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 13 mlearn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 58 m 12 sec
Reputation Power: 0
Huh?

Quote:
Originally Posted by andy11983
Hi,

I was just wondering if it is possibly to set a variable from withina query.

e.g
<cfquery name ="somequery">
select name,age,phone from sometable

<cfset myvar1 = age>
</query>

I need the colum from this table to be set to that variable name so i can pass it through my documents.

Thanks

Andy


I guess the big question is why would you want to set a variable from inside a query? Why can you not just wait until you get the query results to set the variable?

I think that if you answer that, we might be able to help you more...

-Matt

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > declaring variables from within a query


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 6 hosted by Hostway
Stay green...Green IT