I am doing calculation part in SQL for my web app,
I have some scalar variables:
declare @calc as bigint
declare @paymentid as nvarchar(50)
and I am using the variables like this
set @calc =(SELECT REPLACE(CONVERT(CHAR(30), '2017-09-02', 103), '-', ''))
This line removes '-'
and sets the value in @calc
to (20170902)
set @calc = (SELECT SUBSTRING(CONVERT(char(30), '2017-09-02',112), 3, 8))
This line is fetching 170902
and sets the value in @calc
to (170902)
set @paymentid = CAST(@calc as nvarchar(max))+'0001'
and this line will set the value of paymentid
to (1709020001)
But I am getting an error on this line
set @calc = (SELECT SUBSTRING(CONVERT(char(30), '2017-09-02',112), 3, 8))
and the error is:
Msg 8114, Level 16, State 5, Line 4
Error converting data type varchar to bigint
My whole code looks like this
declare @calc as bigint
declare @paymentid as nvarchar(50)
set @calc =(SELECT REPLACE(CONVERT(CHAR(30), '2017-09-02', 103), '-', ''))
set @calc = (SELECT SUBSTRING(CONVERT(char(30), '2017-09-02',112), 3, 8))
set @paymentid = CAST(@calc as nvarchar(max))+'0001'
Replace
to