-1

I have a table defined as class - Id, Date, Time, Session, Remark Int is auto incremented Date,Time and Remark will be added automatically

Session should be the concatenate of (Date + Time)

Suppose Date and Time is varchar(50)

Insert into class (Date,Time,Session,Remark) Values ('a','b', Concat(Date + Time),'c')

Example:
Date - 12/12/2012
Time - 9:00 - 11:00am
Then --> Session - 12/12/2012 9:00-11:00am

3 Answers3

0

Why not you have used CONCAT if Session is VARCHAR data type

INSERT INTO t VALUES(CONCAT('2019-01-12', '12:00'))
R. García
  • 815
  • 9
  • 20
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
0

You can simply write like following query if you are using proper data types, Date for [Date] and Time for [Time].

INSERT INTO [YOUR_TABLE]([DATE], [TIME], [SESSION], REMARK)
VALUES (@DATE, @TIME, CAST(@DATEAS DATETIME) + CAST(@TIME AS DATETIME),@REMARK)
PSK
  • 17,547
  • 5
  • 32
  • 43
0

You can also try this

CREATE TABLE #date (dt datetime)

declare @date Varchar(20) ='2019-01-29' 
declare @time Varchar(20)='11:06:31.095' 

INSERT INTO #date 
    SELECT CONVERT(datetime,Cast(@date as Datetime))+ CONVERT(datetime,Cast(@time as Datetime))

select * from #date

You can replace @date with date column and @time with time column.

Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42