SQL: help assigning value to temp column for results from 2 fields


J

JaneLeigh

Hi
I am trying to assign a value to a temp column for something based on 2
other columns.

Select ID, Imm, Ell
From table_1
where Imm='Y' OR Ell='Y'

I want the column to report an E if or an I. Where and How do I declare?
 
Ad

Advertisements

S

Sylvain Lafontaine

If this is with an Access MDB or ACCDB database file, you could use the IIF
function:

Select ID, Imm, Ell, IIF (Imm='Y', 'I', 'E') as Expr1
From ...


For SQL-Server, you will need to use the Case statement:

Select ID, Imm, Ell, Case When Imm='Y' Then 'I' Else 'E' End as Expr1
From ...

Of course, if both Imm and Ell equal 'Y', then the above solutions might not
be what you want to get.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top