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 December 17th, 2004, 04:42 PM
elfy elfy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Poland
Posts: 11 elfy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 7 sec
Reputation Power: 0
Hi

I'm new in SQL. I have a big problem

Database: MSSQL 2000

I have two tables: (results) one with numeric results and one with names (importance_scale)

SELECT * FROM results

name i1 i2 i3 i4 i5
---- ---- ---- ---- ----
john 2 1 2 2 2
anna 0 2 2 2 2
phil 2 2 2 2 2
dave 1 0 2 2 2

SELECT * FROM importance_scale

imp_value imp_name
--------- ------------
2 very important
1 important
0 not important

i1,i2 etc. value it is a imp_value from table 'importance_scale'

I would like to make report which will show all results in this format (in example only first record):
name i1 i2 i3 i4 i5 etc.
----- --- --- --- --- ---
john very important important very important very important very important etc.

I was thinking about using CASE I don't want use cursor. What is the best way?

Thanks for your help

Reply With Quote
  #2  
Old December 17th, 2004, 10:26 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,953 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 36 m 41 sec
Reputation Power: 1024
Code:
select name
     , n1.imp_name as imp1
     , n2.imp_name as imp2
     , n3.imp_name as imp3
     , n4.imp_name as imp4
     , n5.imp_name as imp5
  from results
inner
  join importance_scale as n1
    on i1 = n1.imp_value       
inner
  join importance_scale as n2
    on i2 = n2.imp_value       
inner
  join importance_scale as n3
    on i3 = n3.imp_value       
inner
  join importance_scale as n4
    on i4 = n4.imp_value       
inner
  join importance_scale as n5
    on i5 = n5.imp_value 
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon

Reply With Quote
  #3  
Old December 18th, 2004, 07:57 AM
elfy elfy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Poland
Posts: 11 elfy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 7 sec
Reputation Power: 0
Thumbs up

Big Thanks!!! This is exactly what I was looking for

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > name lookup 5 times


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