Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
badsy
Starting Member
1 Post |
Posted - 2006-01-10 : 23:41:35
|
HiI've developed this program in C#.netwhere through a querry string dinamically values are inserted to a SQL Server 2000 database,eg: querryString ="INSERT INTO People Values ("+ID+",'"+Name+"','"+Married_Date+"')";But there is a problem if the Married_Date variable is null the will be passed as ,'')";Because of this in the table the value that is inserted is1900-01-01 00:00:00.000 > But this is not I wantI need to store a null value > NULLHow to solve this???Please helpe it is very Urgent!!!!!!!! Please send any solution to dnranatunga@yahoo.com |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-10 : 23:51:37
|
| Accordign to the link there is a new null coalescing operator '??'. It might be usefulhttp://x5.tsiokos.com/posts/2005/08/27/isnull-in-c/-----------------'KH'Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-01-11 : 00:04:53
|
Use the NULLIF function.NULLIF ( expression , expression ) Returns a null value if the two specified expressions are equivalent.CODO ERGO SUM |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-01-11 : 08:46:33
|
| Your problem is that you are passing in the value '' which is implicitly converted to the datetime "equivalent" of 0, which is 1-1-1900 12:00:00AM. You need to pass in the literal NULL (no quotes) to insert a NULL into a column.However: Do not build strings this way and execute them! Use parameters and/or stored procedures and you will never have these (or other) problems.... |
 |
|
|
|
|
|