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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Default value notbeing saved using NULLIF

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-10-11 : 12:40:20
Front end logic in a webpage
1)when i check a check box and submit a page the value that should be getting saved to a datetime feild is getdate() (This logic works ok)
2)When i dont check the check box and submit the webpage a default value of 1/1/1900 should be getting saved but null is getting inserted instead(Not Working)
3)This particular datetime feild should only get updated if i check the checkbox and submit the page and should not be updated if i dont check the check box(This logic also working ok)

Below is the SQL i have been using for the above three conditions

detdate =COALESCE(NULLIF(@detdate,'19000101'),detdate),


How do i modify the above code to accomplish the second condition above

rajarajan
Starting Member

48 Posts

Posted - 2011-10-11 : 12:55:12
check in the table whether allow null is selected
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-10-11 : 13:02:27
Allow null is selected in the table
quote:
Originally posted by rajarajan

check in the table whether allow null is selected

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-11 : 14:29:57
thats because of this

NULLIF(@detdate,'19000101')

you're asking it to make it null value if passed value in @detdate is 19000101
if you want to save the value itself do like

detdate =COALESCE(@detdate,detdate)

i hope you're implemeting the GETDATE() assignment in webpage itself

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-10-11 : 14:54:30
Getdate is being implemented at the page

the below worked
detdate = case when ISNULL(@detdate,'19000101') >= ISNULL(detdate,'19000101')
Then ISNULL(@detdate,'19000101')
Else
detdate
End
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-12 : 01:36:24
ISNULL is equivalent to coalesce but with small implementation differences

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2011-10-12 : 08:16:14
Thank You.It was very useful
quote:
Originally posted by visakh16

ISNULL is equivalent to coalesce but with small implementation differences

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-12 : 08:38:45
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -