Avatar of PeterBaileyUk
PeterBaileyUk
 asked on

sqlserver datetime conversion error

I am trying to insert into a table but its giving me an error message and I dont know how to deal with it.

the columns in the destination are as per attached

word is a string containing one wordof nvarchar(50)
MyDateTime is the date and time
the primary key is made up of the word and datetime.


Msg 241, Level 16, State 1, Line 3
Conversion failed when converting date and/or time from character string.

use Dictionary

insert into TblCurrentWords (Word_ID, Word, MyDateTimeCol)

select Word + GETDATE() AS CurrentDateTime, word, GETDATE() AS MyDateTimeCol
from TblWords
where word is not null and PATINDEX('%[0-9]%',Word)=0
group by word
order by word

Open in new window

ex
Microsoft SQL Server

Avatar of undefined
Last Comment
PortletPaul

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PeterBaileyUk

ASKER
Thankyou once again
PortletPaul

the primary key is made up of (a concatenation of) the word and datetime.

That is NOT a good way to define the table

You could make the unique key a combination of word and a datetime column, but do not concatenate them
PortletPaul

oh no too late...
Your help has saved me hundreds of hours of internet surfing.
fblack61