Solved

sql query for null value

Posted on 2016-07-26
2
39 Views
1 Endorsement
Last Modified: 2016-07-26
Hello,


Datetime column inserting 1/1/1900 for null value

Have a code ,which does job for time but not date

[PickUpTime]  = CASE when @PickUpTime= '' then NULL else CAST(@PickUpTime  AS  nvarchar(20)) end ,  


Cheers
1
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 41729520
Eyeball this table in table design and see if the column is defined NOT NULL, and if so you'll need to change it to allow NULLs.

Right-click on table > Script Table As ... > Create To > New Query Window Editor..

-- Change the column definition to allow NULLs
ALTER TABLE YourTableName
ALTER COLUMN PickUpTime datetime NULL

Open in new window


>Datetime column
>CAST(@PickUpTime  AS  nvarchar(20)) end ,  
So which is it ... a datetime column or a nvarchar(20)) column?  Storing date values in a varchar column is a poor programming practice as it will allow all sorts of values that are not convertable to dates, which will throw an error.
1
 

Author Closing Comment

by:RIAS
ID: 41729527
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question