SQL Language Question 
Author Message
 SQL Language Question

I'm not sure if this can be done or not in SQL, I know I can do it with
code, but I'd rather use just sql if I can.

I've got a table, let me use this example for instance

mBob
fJulie

I want to create a new table based on the information in this one, only that
if the first letter of the name "mBob or fJulie" is a 'm' then in the new
table, create a Sex field with 'male', or if there is a 'f' there, in the
sex field create 'female'.  My question is, how would I do this in SQL.  I
know I can use the LIKE operator, but i've never done it for two different
values, for only one field.

Any help would be appreciated!

Michael



Sat, 22 May 2004 04:04:33 GMT
 SQL Language Question


CASE
WHEN LEFT(Name,1) = 'F' THEN


END

Pieter


Quote:
> I'm not sure if this can be done or not in SQL, I know I can do it with
> code, but I'd rather use just sql if I can.

> I've got a table, let me use this example for instance

> mBob
> fJulie

> I want to create a new table based on the information in this one, only
that
> if the first letter of the name "mBob or fJulie" is a 'm' then in the new
> table, create a Sex field with 'male', or if there is a 'f' there, in the
> sex field create 'female'.  My question is, how would I do this in SQL.  I
> know I can use the LIKE operator, but i've never done it for two different
> values, for only one field.

> Any help would be appreciated!

> Michael



Sat, 22 May 2004 04:18:01 GMT
 SQL Language Question
This is off the top of my head without running an actual test but I think
this is what you are after

insert into NewTable (Name, Sex)
  select substring(Name, 2, datalength(Name) - 1),
    case substring(Name, 1, 1)
      when "m" then "male"
      when "f" then "female"
      else "x"
    end
  from OldTable

--
Steve
http://www.krell-software.com
Database Development Tools for MS SQL Server


Quote:
> I'm not sure if this can be done or not in SQL, I know I can do it with
> code, but I'd rather use just sql if I can.

> I've got a table, let me use this example for instance

> mBob
> fJulie

> I want to create a new table based on the information in this one, only
that
> if the first letter of the name "mBob or fJulie" is a 'm' then in the new
> table, create a Sex field with 'male', or if there is a 'f' there, in the
> sex field create 'female'.  My question is, how would I do this in SQL.  I
> know I can use the LIKE operator, but i've never done it for two different
> values, for only one field.

> Any help would be appreciated!

> Michael



Sat, 22 May 2004 04:18:06 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. sql language question ( i hope this is the right NG)

2. Basic SQL language question

3. SQL language question

4. Open Sql language Question

5. SQL language [simple] question...

6. Question about language strings used by SQL Server

7. Question about languages in SQL

8. Question about the language string used in SQL Server

9. Question about setting SQL Server language.

10. Question about setting SQL Server language.

11. SQL*TextRetrieval question:Foreign Language support

12. Language features question - SQL/92


 
Powered by phpBB® Forum Software