I'm not to good in programming sql,
what i want to do is select 3 columns from 4 possible,
what i mean is that i have 2 columns in the DB that i need to select
only one of them everytime(one of them is null, but i can't no each row
which one)
and i need the result (the one that is not null) to be in a column
select into is my answer? i don't know how to use it...
plz advice.
And if you if it will work on sql mobile would be great aswellUse CASE , check SQL Books Online. This gives you the capacity to select
different columns depending on what values exist in the column(s)
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
<chook.harel@.gmail.com> wrote in message
news:1149669940.164598.26800@.i39g2000cwa.googlegroups.com...
> I'm not to good in programming sql,
> what i want to do is select 3 columns from 4 possible,
> what i mean is that i have 2 columns in the DB that i need to select
> only one of them everytime(one of them is null, but i can't no each row
> which one)
> and i need the result (the one that is not null) to be in a column
> select into is my answer? i don't know how to use it...
> plz advice.
> And if you if it will work on sql mobile would be great aswell
>|||I'm not sure , so just a guess
SELECT col1,col2 +COALESCE(col3,'') AS bla FROM Table
<chook.harel@.gmail.com> wrote in message
news:1149669940.164598.26800@.i39g2000cwa.googlegroups.com...
> I'm not to good in programming sql,
> what i want to do is select 3 columns from 4 possible,
> what i mean is that i have 2 columns in the DB that i need to select
> only one of them everytime(one of them is null, but i can't no each row
> which one)
> and i need the result (the one that is not null) to be in a column
> select into is my answer? i don't know how to use it...
> plz advice.
> And if you if it will work on sql mobile would be great aswell
>|||Use COALESCE - check in BOL.
"chook.harel@.gmail.com" wrote:
> I'm not to good in programming sql,
> what i want to do is select 3 columns from 4 possible,
> what i mean is that i have 2 columns in the DB that i need to select
> only one of them everytime(one of them is null, but i can't no each row
> which one)
> and i need the result (the one that is not null) to be in a column
> select into is my answer? i don't know how to use it...
> plz advice.
> And if you if it will work on sql mobile would be great aswell
>|||Use
isnull or coalesce
check in BOL|||Thanks very much for the quick answers,
but from what i've read the COALESCE function still gets only one
paramater..
My thing is to differ from the columns and at the end show only one...|||ooops
I've missread,
Thanks alot! I'll check it out and return with my findings :)
chook.ha...@.gmail.com wrote:
> Thanks very much for the quick answers,
> but from what i've read the COALESCE function still gets only one
> paramater..
> My thing is to differ from the columns and at the end show only one...|||Hehe So I now understand that the COALESCE function checks for NULL
but when I have a null field i've put an empty string there, so it
still gets it
is there a way for the sql to interpert the empty string "" as null?
or should I rewrite my code, so that "" will go as NULL to the db.|||then you will have to use a case.
Say you want to take the non null value between two columns col2 and col3
select case isnull(col2,'') when '' then col3 else col2 end as non_null_col
from tbl1
But if both col2 and col3 are null, then it will give u a null.
You can extend this to more than 2 columns..
Hope this helps.|||On 7 Jun 2006 02:42:00 -0700, chook.harel@.gmail.com wrote:
>Hehe So I now understand that the COALESCE function checks for NULL
>but when I have a null field i've put an empty string there, so it
>still gets it
>is there a way for the sql to interpert the empty string "" as null?
>or should I rewrite my code, so that "" will go as NULL to the db.
Hi Chook,
NULLIF (TheColumn, '')
will return NULL if TheColumn contains an empty string. Otherwise, the
contents of TheColumn is returned.
Hugo Kornelis, SQL Server MVP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment