?
Solved

sql query for null value

Posted on 2016-07-26
2
Medium Priority
?
42 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

770 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