Solved

sql query for null value

Posted on 2016-07-26
2
38 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 65

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
push and Pull replication 31 48
SQL Server Resume 5 46
T-SQL Query - Group By Year 3 32
SQL Server Express automatically execute SQL or SP 8 35
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

733 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