Question : datetime error date - SQL

Hello All - I have a temp table and I need to insert data there, and I keep getting this error:
Server: Msg 8115, Level 16, State 2, Line 16
Arithmetic overflow error converting expression to data type datetime.
The statement has been terminated.

On the database the Date of Birth and Referral_Date are both datetime (8)
see below the code

any idea?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
CREATE TABLE #tbl_Referral
        (

		 User_idT  int NULL,
		 LastName nvarchar (50) Null,
		 FirstName nvarchar(50) NULL,
		 Gender nvarchar(50) NULL,
		 DOB datetime,
		 Date_Referral datetime,
  		 Status nvarchar(50) NULL,
		 Location nvarchar(50) NULL
	      
	)


Insert into #tbl_Referral( User_idT, LastName, FirstName,  Gender,
DOB, Date_Referral, Status)
 
 (Select  ID, LastName, FirstName, Gender, DateOfBirth, 
  DateOfReferral, Status



	FROM tbl_Referral )

Answer : datetime error date - SQL

Check the following:

  1. Are the tbl_Referral date columns actually VarChar() or Char() columns instead of datetime columns?
    If so, use CONVERT(DateTime, DateOfReferral, 100) and CONVERT(DateTime, DateOfBirth, 101)  in your SELECT statement.
     
  2. Are there any NULLs in the date columns in your data?
    If so, you will need to do one of hte following: 
    1. Allow the temp table's date columns to be NULL; 
    2. Set a DEFAULT value for those columns in your temp table definition; 
    3. Change your SELECT statement so that it uses a CASE to test for the dates being NULL and places them with a default value. 
Random Solutions  
 
programming4us programming4us