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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 3rd, 2004, 12:43 PM
jmlsgateway jmlsgateway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: OKC
Posts: 342 jmlsgateway User rank is Private First Class (20 - 50 Reputation Level)jmlsgateway User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 20 h 48 m 28 sec
Reputation Power: 5
Reading Multiple Values from a Table

I am working in SQL Server, so I think I am in the right place! My question is, I have a table that is called CustomSearchListBox. Bascially, it is a table that converts that various abbreviations that I use into their full names. Such as city and county.

Here is what I have for a query

SELECT Prp.IdNum, CustomSearchListBox.Label As City

FROM Prp INNER JOIN CustomSearchListBox ON Prp.City = CustomSearchListBox.[Value]

WHERE prp.IdNum = 123456 AND CustomSearchListBox.FieldName= 'City'


This will return the item number and the name of the city(instead of the two letter abbrevation in the prp table) that the item is in. But now I also need to return the county the item is in too. How would I do the FROM part and WHERE part of the SQL statement. I tried just adding a CustomSearchListBox.Label As County and then added another INNER JOIN AND WHERE statement but I get an error saying

Tables or functions 'CustomSearchListBox' and 'CustomSearchListBox' have the same exposed names. Use correlation names to distinguish them.

Thanks in advanced!

Reply With Quote
  #2  
Old May 3rd, 2004, 10:11 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
what table is the 'County' field in??

Reply With Quote
  #3  
Old May 3rd, 2004, 10:35 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,343 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 5 m 22 sec
Reputation Power: 891
Code:
select Prp.IdNum
     , CityBox.Label    as City
     , CountyBox.Label  as County
  from Prp 
inner 
  join CustomSearchListBox as CityBox
    on Prp.City 
     = CityBox.[Value]
   and CityBox.FieldName= 'City'
inner 
  join CustomSearchListBox as CountyBox
    on Prp.City 
     = CountyBox.[Value]
   and CountyBox.FieldName= 'County'
 where prp.IdNum = 123456 

notice the correlation names CityBox and CountyBox to distinguish the two "copies" of the table
__________________
r937.com | rudy.ca

Reply With Quote
  #4  
Old May 4th, 2004, 09:08 AM
jmlsgateway jmlsgateway is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: OKC
Posts: 342 jmlsgateway User rank is Private First Class (20 - 50 Reputation Level)jmlsgateway User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 20 h 48 m 28 sec
Reputation Power: 5
Thumbs up

THANK YOU so much!! Your solution worked great!!! Thanks for the help and the quick response!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Reading Multiple Values from a Table


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 3 hosted by Hostway