February 22, 2009 at 3:15 pm
Hi,
i have a problem with select statement
i create a databse using sql server 2005 like this
id firstname lastname address phone trainingdate qualifieddate graduatedate
1 andy edwards 11 main street 123456 12/12/2008 12/12/2008 12/02/2009
2 jones langham 12 queen road 112233 null 10/02/2007 null
3 sam edwards 13 cuba street 123331 null null null
4 james murray 11 cuba street 865522 null null null
6 ashley cole 10 wilis street 786876 null null null
how can i make a select statement that dont display training date and qualified date for jones (id 2)
i know that you can do this, but in my case, i cant make this sql statement:
select id, firstname, lastname, address, phone, graduatedate from Member where member id = 2
the one that i need is a select statement that select the whole rows
select id, firstname, lastname, address, phone, trainingdate, qualifieddate, graduatedate from Member where member id = 2
but do not display if the trainingdate and qualified date if there are any null field
can anyone help me please
thank you
February 22, 2009 at 3:51 pm
This is something that has to be dealt with at the application level. You either return the data in your select or you don't.
At the application level, it's easy to do something like... if data is null then show "No data".
I hope this helps.
February 22, 2009 at 3:58 pm
i am developing aspx with c#
so where should i put the code
in the application level, you mean in the design
not in the code
and how i suppose to implement that
thank you
February 22, 2009 at 4:35 pm
I don't know aspx code very well. That's going to be where you do a response.write or when you assign the value from the select to a label or textbox.
Maybe you should checkout http://www.w3schools.com and find a good aspx tutorial on the site.
February 22, 2009 at 4:53 pm
is it a good idea to make the date dataype smalldatetime into string ?
because if the date = null or empty, it gives me 1/01/1900
which is i can not update the database if the is like 1/01/1900
i can update the database using C# if the date is in correct format like 12/12/2009 it works
but when it comes to 1/01/1900 the update fail
any suggestion about this?
thank you
February 22, 2009 at 4:55 pm
every null date type change into 1/01/1900
how to make the date null instead of empty
if the date null i can update database easily
February 22, 2009 at 5:17 pm
Before setting the control value you can check to see if the date is 1900/01/01. If it is, then show nothing, else chow the date.
Then when comes time to update the data back into the table, if the date ="" then send NULL, else send the date.
February 22, 2009 at 5:33 pm
well actually the date is null
but when the update button pressed, all the null date change to 1/01/1900
that is why i have been wondering whether i can use the select statement to unselect the empty field
so it appears empty instead 1/01/1900
because once you press the button, the textbox is filled with 1/01/1900
if i can use select statement to select all fields except for the null ones, my problem solved
otherwise i have to change smalldatetype into string
i already test with string and it works perfect
if i can ask your opinion ninja, how you do that select statement
select * from Member Where id = 1 and (not include the null value)
thank you
regards,
ayi
February 22, 2009 at 6:18 pm
Can't be done... easily anyways.
Change to string if you must. Make sure you are aware that dates are not displayed the same way from one computer to another. Take that in consideration into your coding.
Also I'm sure there's a way around that problem... you're not the first person using null dates in aspx.
Good luck.
February 22, 2009 at 6:25 pm
well thank you so much for the help
yeah, i will change the date datatype into string and the other reason is that i dont need the hourly format
best regards,
ayi
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy