MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS 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 October 16th, 2009, 03:41 PM
techboyjk techboyjk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Location: St. Louis
Posts: 95 techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level)techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level)techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level)techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level)techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level)techboyjk User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 20 h 17 m 24 sec
Reputation Power: 22
Variables to UNION clause???

Hi Guys,

I have a series of tables for classified ads.. Each core category has it's own table. Since each category's actual listing page requires a different URL, I'm having trouble trying to figure out how to include different URLs when I list the results of a Union query.

Because I want ALL classifieds, when the user is viewing their listings, to be combined into a single record set, I am going to do a Select/UNION ALL


<CFQUERY NAME="all_listings" datasource="classifieds">

SELECT
id as classified_id,
title as classified_title,
created as classified_created,
category_a as classified_category_a

FROM announcement_classifieds

UNION ALL

SELECT
id as classified_id,
title as classified_title,
created as classified_created,
category_a as classified_category_a

FROM aircraft_classifieds

WHERE member_id = '#MYID#'
;

</CFQUERY>


When the query results are displayed, the Title column will include the results as links, so that the user can click on the title to see the actual classified ad. While part of the query returns the unique ID for each classified ad, the ID is only unique to that table.

Is there a way I can include an attribute to each record in the query result that differentiats which table it came from?

Again the reason is the URL to view each classified ad is slightly different for each main category.

ex. company.com/view_aircraft_ad.cfm?id=1232
company.com/view_apartment_ad.cfm?id=1232


I want to be able to include the URL like company.com/view_#category#_ad.cfm?id=1232 and depending on which table the record came from, declare the category.

Reply With Quote
  #2  
Old October 16th, 2009, 04:26 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,985 swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level)swampBoogie User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 19 h 32 m 46 sec
Reputation Power: 151
Code:
SELECT
id as classified_id,
'announcement' as whichtable,
title as classified_title,
created as classified_created,
category_a as classified_category_a

FROM announcement_classifieds

UNION ALL

SELECT
id as classified_id,
'aircraft',
title as classified_title,
created as classified_created,
category_a as classified_category_a

FROM aircraft_classifieds

WHERE member_id = '#MYID#'


Thus you will get an extra column named whichtable in the result.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Variables to UNION clause???


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-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek