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
 Data Conversion - using case expressions

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-09-27 : 14:33:15
I have a series of excel sheets from which i am converting data into our SQL 2008 database. Some of the fields in the excel files provided by the customer contain fields that are varchar(3). One example is that these describe "skin tone", and include abbreviations such as "DRK", "PAL", "RUD", etc. in our database, these fields are bit fields, with one for each description. I am assuming that, in order to convert these, a case expression needs to be composed, but i am unclear as to the syntax to be used in this situation. Any help is appreciated.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-09-27 : 15:35:34
perhaps this:

select isDRK = case when [skin tone] = 'DRK' then 1 else 0 end, isPAL = case when [skin tone] = 'PAL' then 1 else 0 end, etc...

Be One with the Optimizer
TG
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2011-09-27 : 15:47:35
I'm currently using "INSERT INTO" lines within the query identifying the columns to which the new data belongs followed by corresponding values in the same line (VALUES) for the actual data. Would I place the same case value syntax after each line which imports the other data or would i just place the column names in the INSERT TO line along with the other and some syntax to reference the case expression as it relates to those columns? The latter assumption is that the case expression happens only once in the query. I'm unclear (obviously) as to how to work the CE into the query for this situation.

thanks again
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-09-27 : 15:57:56
Post your source and target DDL (scripted CREATE TABLE statements) and the code you've got so far.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -