Need help with 'convert' in 'insert into' statement

Please help with the error I'm getting trying to convert varchar to datetime in an INSERT INTO statement.

Microsoft SQL Server 2012 on a Windows Server 2012r2 machine.

Thanks.

Here's the statement with the error:

insert into replication2 (VMName, PrimaryHost, ReplicaHost, convert(datetime, LastReplicaDate,103) )
select VMName, PrimaryHost, ReplicaHost, LastReplicaDate from replication

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'convert'.

Here are the two tables replication (the source, 1531 rows) and replication2 (empty, 0 rows):
---------------------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[replication](
      [id] [smallint] IDENTITY(1,1) NOT NULL,
      [VMName] [varchar](50) NULL,
      [PrimaryHost] [varchar](50) NULL,
      [ReplicaHost] [varchar](50) NULL,
      [LastReplicaDate] [varchar](50) NULL,
 CONSTRAINT [PK_replication] PRIMARY KEY CLUSTERED
----------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[replication2](
      [id] [smallint] IDENTITY(1,1) NOT NULL,
      [VMName] [varchar](50) NULL,
      [PrimaryHost] [varchar](50) NULL,
      [ReplicaHost] [varchar](50) NULL,
      [LastReplicaDate] [datetime2](7) NULL,
 CONSTRAINT [PK_replication2] PRIMARY KEY CLUSTERED
----------------------------------------------------------------------------------------------------------------

Here is a sample 8 rows from the source table:

select * from replication
where vmname = 'vm100'

id      VMName      PrimaryHost      ReplicaHost      LastReplicaDate
9096      vm100      hostA      hostB      6/6/2015 7:52
10096      vm100      hostA      hostB      6/7/2015 8:56
11096      vm100      hostA      hostB      6/7/2015 8:56
12096      vm100      hostA      hostB      6/8/2015 16:14
13096      vm100      hostA      hostB      6/10/2015 10:46
14096      vm100      hostA      hostB      6/11/2015 1:16
15133      vm100      hostA      hostB      6/4/2015 6:59
16096      vm100      hostA      hostB      6/11/2015 1:31
gateguardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>insert into replication2 (VMName, PrimaryHost, ReplicaHost, convert(datetime, LastReplicaDate,103) )
The INSERT INTO statement demands only column names between the parentheses marks, and the convert is an expression.   Perform any expression such as convert in the SELECT / VALUES section of an INSERT statement, like this..

INSERT INTO replication2 (VMName, PrimaryHost, ReplicaHost, LastReplicaDate)
SELECT VMName, PrimaryHost, ReplicaHost, convert(datetime, LastReplicaDate,103)
FROM replication

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gateguardAuthor Commented:
I'm still having trouble with the actual conversion but you set me straight on where to put the convert statement in the insert into, so I'm closing this question and I'll ask another.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.