Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement help on poorly designed database

Status
Not open for further replies.

jaybuffet

Technical User
May 22, 2003
31
US
I am working on a site that is in production, so I can't change the tables. The way it is nowI have 3 tables.

1. tblNumbers
Code:
num
---
 1
 2
 3

2. tblImpacts
Code:
num     a     b     c
----------------------
 1      1     0     1
 2      0     1     1
 3      1     1     1

3. tblImpactDecode
Code:
code     decode
---------------
  a       'this is a'
  b       'this is b'
  c       'this is c'

So I have to make a statement that does an inner join on the tblImpact columns = tblImpactDecode.code

So if I select tblNumbers.num = 1
the results would be
Code:
num     decode
 1       'this is a'
 1       'this is c'


is there a SQL statement or a stored procedure

please help

thanks
jason
 
I thought of the Union statement...
Something like this:

select num, decode
from tblimpacts
inner join tblImpactDecode
on code = 'a'
where a = 1
and num = 1
union
select num, decode
from tblimpacts
inner join tblImpactDecode
on code = 'b'
where b = 1
and num = 1
union
select num, decode
from tblimpacts
inner join tblImpactDecode
on code = 'c'
where c = 1
and num = 1

Not sure if that works for you or not.
 
That would work., but I was looking for more of a dynamic solution since there could be up to 15 columns
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top