School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,578 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,204 people online right now. Registration is fast and FREE... Join Now!




Joining to columns and using an alias.

 

Joining to columns and using an alias.

xheartonfire43x

7 Apr, 2009 - 05:59 AM
Post #1

D.I.C Regular
***

Joined: 22 Dec, 2008
Posts: 260



Thanked: 2 times
My Contributions
I am buidling a form and basically I am having it do one query and if that doesn't return the necessary information it queries another table to get it.

CODE

<cfquery name="reservationinfo" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
    SELECT pickupdate,pickuptime,pickupfrom,pickupname,pickupcompany,pickupaddress,pickupsu
ite_flr_apt,pickupcity,pickupstate,chauffeurmeet,pickupairportname,pickupairline
terminal,pickupflightnumber,pickupdeparturecity FROM travelreservations WHERE cuuid = <cfqueryparam value="#session.cuuid#"> AND rid = <cfqueryparam value="#session.rid#">
</cfquery>
<cfif reservationinfo.pickupdate lte "">
    <cfquery name="reservationinfo" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
        SELECT fname,
                     lname,
                     company AS pickupcompany,
                     address1 AS pickupaddress,
                     address2 AS pickupsuite_flr_apt,
                     city AS pickupcity,
                     state AS pickupstate
        FROM travelMembers WHERE     cuuid = <cfqueryparam value="#session.cuuid#">    
    </cfquery>
    <cfset reservationinfo.pickuname = #reservationinfo.fname# & "&nbsp;" & #reservationinfo.lname#>
    <cfquery name="reservationinfo" datasource="#mydatasource#" username="#myusername#" password="#mypassword#">
        SELECT pickupdate,pickuptime,pickupfrom,chauffeurmeet,pickupairportname,pickupairlinete
rminal,pickupflightnumber,pickupdeparturecity FROM travelreservations WHERE cuuid = <cfqueryparam value="#session.cuuid#"> AND rid = <cfqueryparam value="#session.rid#">
    </cfquery>
</cfif>
<cfdump var="#reservationinfo#">


On the first SQL query after the CFIF statement I need fname and lname to be joined as pickupname. I would just use a bunch of CFSET's and use those variables but at this point that would be too much code that I only want to do if need be. So I don't know if there is a SQL keyword that I could use for it or not but thanks for your help.

User is offlineProfile CardPM
+Quote Post


sansclue

RE: Joining To Columns And Using An Alias.

7 Apr, 2009 - 08:15 AM
Post #2

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 times
My Contributions
The concatenation operator varies by database. For MS SQL it is "+":

SELECT fName +' '+ lName AS PickupName
.....


BTW, it may not apply here but if even one of the values you are concatenating is NULL, then the final value will also be NULL.

This post has been edited by sansclue: 7 Apr, 2009 - 08:16 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:19AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month