Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Complex CASE statements

Author  Topic 

buttonjockey
Starting Member

1 Post

Posted - 2012-01-06 : 12:05:59
Hi Folks

I want to generate 3 columns of (new) data for [Territory], [Country] and [Region] in a query based on 4 or more text fields in a large table (10,000,000+ rows). A combination of two columns [Peril] (e.g. Earthquake 'EQ' or Flood 'FL') and [Region] (e.g. North America 'NA' or Europe 'EU') gives 72 unique combinations and for each possibility the logic for creating the 3 new columns is different. Other than an horrific CASE statement, can anyone think of doing this a better way? I thought of storing the logic for each new field for each of the 72 combinations as a text string in a lookup table, but can't think of a way to execute this text in the query. Any help appreciated...

P.S. As a newbie to SQL Team, i can't tell you how helpful this site has been to my SQL development over the last 2 years, so thanks everyone.

...just another cog in the machine

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-06 : 12:18:32
Without the basics (DDL, DML and expected output) it's hard to offer much. One suggestion might be to create some sort of mapping table that maps Peril and Region to three new columns and then join to that.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-06 : 12:35:16
read the hint in my sig...but try and keep it simple

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -