Friday, March 9, 2012
How can this be done...
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
Friday, February 24, 2012
How can I use mdf files from sql server 2005 exp. edition.
Hello,
I am a candidate for web programming..I would like to desing a website and I have a good host which is supporting .net 2.0 and sql server 2005 service. So I would like to ask you
1) how can I use sql server express edition's mdf database file there. or Can I store and use this "mdf"s in ftp folder? What should I do. ..
2) I have only one database "right" there and should I manage everything in one database. For example asp.net configuration manager created ASPNETDB.mdf and ldf...so if Can you inform me about this issue?
Maybe my questions is not advance, they are very basic but I want to learn
Thank you very much for your helps.
Hi,
From your description, it seems that you want to deploy the database in your SQLExpress to the SQLServer2005 database on your host server, right?
If so, I suggest that you should use some tools to achieve that instead of attaching MDF manually. First, you may use aspnet_regsql.exe tool convert the database in SQLExpress to your local SQLServer series database. In you case it's SQLServer2005. After that, use SQLServer export and import wizard to upload the database (including table and schema) to the SQLServer2005 instance on your server.
For aspnet_regsql.exe, see:
http://msdn2.microsoft.com/en-us/library/ms229862.aspx
Thanks.