How Can I use Date Datatype in sql server

0 votes

When I'm trying to create column in table with data type "Date" it is giving me error 

Create table Sales (
Order_ID INT Primary Key,
Product_name varchar(100) ,
isbn varchar(100) ,
Customer_ID INT Foreign key references Customer,
Order_date date,
);

I need to get date of something which is before created one

The query indicates to find the date before 2nd August

The code I have used is:

Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (1, 'Design User Interface',9345678210123, 1, '02-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (2, 'Fire',9654693261489, 1, '05-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (3, 'The Odyssey',9654864332511, 2, '01-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (4, 'Anatomy',9654877777755, 2, '30-07-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (5, 'Surgery',9654864951753, 2, '01-07-2015'); 
it is accepting only the first 3 data insertion and last two it is reporting error
Feb 9 in Database by Vaani
• 5,040 points
46 views

1 answer to this question.

0 votes
There's problem in all of them and not just the last two.

The error is due to the DATE FORMAT
Your system is taking a different date format while your data has a different one.

Your dates are as MM-DD-YYYY which depends on the culture of your system,

While using dates, it is better to use culture independent formats like the universal format:

2020-10-05 is 5th of October 2020
 

Using YYYY-MM-DD format might actually work out for your query.
answered Feb 9 by Neha
• 6,260 points

Related Questions In Database

0 votes
1 answer

What are the different authentication modes in SQL Server? How can it be changed?

Windows mode and Mixed Mode – SQL ...READ MORE

answered Oct 29, 2018 in Database by Sahiti
• 6,360 points
574 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3 in Database by Vaani
• 5,040 points
35 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4 in Database by Vaani
• 5,040 points
12 views
0 votes
1 answer

How can I define a composite primary key in SQL?

A primary key is unique and it ...READ MORE

answered Feb 21 in Database by Vaani
• 5,040 points
33 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9 in Database by Neha
• 6,260 points
53 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16 in Database by Vaani
• 5,040 points
143 views
0 votes
1 answer

How to convert DateTime to VarChar

With Microsoft Sql Server: -- -- Create test case -- DECLARE ...READ MORE

answered Feb 23 in Database by Neha
• 6,260 points
18 views
0 votes
1 answer

How to connect Java program to the MySQL database?

You can connect your Java code with ...READ MORE

answered May 11, 2018 in Java by Parth
• 4,630 points
850 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4 in Database by Neha
• 6,260 points
77 views
0 votes
1 answer

SQL Server replaces LEFT JOIN for LEFT OUTER JOIN in view query

You are getting the joins confused and ...READ MORE

answered Feb 4 in Database by Neha
• 6,260 points
73 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP