0

I am currently getting this error and i am completely lost as to what the issue is. I tracked the error down to a view and completed a select * statement from it and i get that message. Now, the weird thing is is that this error has never appeared on this view before. It has always ran without any issues and nothings been changed so i am unsure as to what the issue is.

I cant show the data for security reasons but it holds 2 date fields that are

 datetime, not null

but i am not trying to change this data in anyway, i am simply just trying to select it.

The only other fields i thought it might concern are

decimal (38,20)

could this be the issue?

Sorry for the lack of information regarding the tables but i have literally tried everything from casting the fields to larger decimals, floats etc and still nothing.

It would be great if there was any small advice anyone could give that would possibly point me in the right direction?

UPDATE

If i do a

select top (1000)

query it works but any larger and i get that error

8
  • is there any data type casting or conversion inside the view? Commented Nov 16, 2017 at 10:04
  • Could you post what the view looks like? I’m betting your datetime field is joining to a non-datetime field. Commented Nov 16, 2017 at 10:04
  • Do u have where clause anywhere in the query ? Commented Nov 16, 2017 at 10:04
  • @AbdulRasheed did you see my update? why would it work with a 1000 limit but not work for everything Commented Nov 16, 2017 at 10:06
  • 1
    You should update your question with a view text. You can substitute table names with T1...Tn if you don't want to show your real table names. There is some join of type varchar = datetime or smth like this Commented Nov 16, 2017 at 10:11

2 Answers 2

2

If using sql server version 2012 or higher, try use TRY_CONVERT function. It goes like

SELECT TRY_CONVERT(datetime, ColumnName).

NOTE: It will return a NULL if ColumnName contains data which can't be converted to a datetime.

Sign up to request clarification or add additional context in comments.

Comments

0

i think there are some wrong date has been inserted in database, you need to use

ISDATE() sql function for same eg. like below in your select query

 (CASE WHEN ISDATE (your_date) = 1 
             THEN convert(datetime, cast([your_date] as char(8)))
             END) AS your_Date

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.