Re: if statement?

From: Aaron Bertrand [MVP] (aaron_at_TRASHaspfaq.com)
Date: 04/27/04


Date: Tue, 27 Apr 2004 13:15:30 -0400

Assuming the values that aren't populated are NULL, and exactly one column
is always populated.

SELECT
    [new column] = COALESCE(col1, col2, col3)
    FROM some_table_name

Usually, it's more helpful to provide CREATE TABLE and INSERT scripts for
sample data, instead of scribblings and narrative...

-- 
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Fab" <flazzaro@tac.infostream.ca> wrote in message 
news:%23CO1QpHLEHA.3052@TK2MSFTNGP12.phx.gbl...
> Hello;
>
> Im trying to put a value in a colomn depending of the value of 3 other
> columns....i.e.
>
>
> col    1    2    3
>        a
>                b
>                    c
> in my new column i want to check the values for each row and return the
> value for the row.
>
> i.e the final table would look like this
>
>
> new column
> a
> b
> c
>
>
> Thanks.
>
>
>
> 


Relevant Pages

  • Re: assigning DB-user to server role
    ... scripts are a lot easier to post here that the GUI steps. ... >> You should be able to grant object permissions to the roles only. ... >> SQL Server MVP ...
    (microsoft.public.sqlserver.security)
  • Re: about automation tool
    ... SQL Server MVP ... > usefil for running all batch file? ... within a SQLCMD file to specify the external scripts in the desired order. ... > hi, my self gautam, i am a DBA. ...
    (microsoft.public.sqlserver.security)
  • Re: about automation tool
    ... party tool which is useful for running all object scripts at one time " OR " ... SQL Server MVP ... I am working on a sqlserver2005 database. ...
    (microsoft.public.sqlserver.security)
  • Re: Number of SQL Server logins
    ... Busy writing some scripts to test what really happens when the 2 tables hit ... Mike Epprecht, Microsoft SQL Server MVP ... >> limit per database. ...
    (microsoft.public.sqlserver.server)