SQL Help please...

danny-t
01-14-2004, 08:53 PM
I'm tryin to query an old database to rearrange it to a format that will fit a newer one with completely different table layouts, field types etc... yeah tryin to hammer a square peg into a round hole! But what client wants...

Anyway being the sql-inept bod that I am I could do with some help on the following. Is there some way that if a record has value x then display value y? E.g. in old db records are given values such as "bus", "mot" and "sal" whereas in the new db these would be 1, 2 and 3. Can I query the old table to say if value is "bus" then show 1 etc.

Hope that makes sense to ya (doesn't to me! :whoops: )

Cheers

mikechan8888
01-14-2004, 09:10 PM
Two ways to do it:

1) Create a mapping table with 2 fields (new and old value)

2) If you are using SQL Server and don't mind hardcoding, try this:

SELECT
CASE f1
WHEN 1 THEN 'bus'
WHEN 2 THEN 'mot'
WHEN 3 THEN 'sal'
END hohoho
FROM Table1


Mike

danny-t
01-14-2004, 09:18 PM
Two ways to do it:

1) Create a mapping table with 2 fields (new and old value)

2) If you are using SQL Server and don't mind hardcoding, try this:

SELECT
CASE f1
WHEN 1 THEN 'bus'
WHEN 2 THEN 'mot'
WHEN 3 THEN 'sal'
END hohoho
FROM Table1


Mike

Thanks, I really should have worked out the whole mapping table thing but its been a while!

Cheers matey! :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum