Solved

sql query for null value

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now