Click here to Skip to main content
16,013,440 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
How select CAST( Codate as datetime) .

What I have tried:

delete my question
Posted
Updated 7-Jun-18 23:52pm
v3
Comments
Maciej Los 19-Oct-14 6:17am    
Please, provide sample data.

Depending on SQL server date format conversion may failed or may succeed.

Try to use SET DATEFORMAT[^] command before SELECT statement.
SQL
SET DATEFORMAT ymd;
SELECT CONVERT(DATETIME, VarcharField) AS MyDateTime
 
Share this answer
 
Hello Friend
As (OriginalGriff) Says...This Is The Same Problem I Coincidence It Should First Check If You Are Change The Default Database Collation If You Change It Then
You Must See My Solution :

Cast([QTE_IN_STOCK] AS Varchar(50))COLLATE DATABASE_DEFAULT
 
Share this answer
 
So don't store dates as strings: it always gives problems.
Store data in "proper" column datatypes: integers in INT, Dates in DATETIME. That way you know the data in your db is always correct - because if it wasn't, it wouldn't be there.

Storing everything in NVARCHAR columns seems easy, but it gives huge problems down the line as you are starting to see.

Bite the bullet and correct your whole DB now, at this early stage - becasue if you leave it too long you will have a large body of code / data which you can;t do anything with!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900