@ bankuaicode varchar (50)
As
Declare @ SQL nvarchar (1000)
Declare @ sql1 nvarchar (1000)
Declare @ sql2 nvarchar (1000)
Declare @ bankuainame nvarchar (100)
Declare @ begintime1 nvarchar (20)
Declare @ sum5 float
The begin
The set @ begintime1=the convert (varchar (10), getdate (), 120)
The set @ bankuainame='zhy + @ bankuaicode
SQL="insert into the set @ + @ bankuainame + '(begintime, bankuaicode dayopen, dayhigh, daylow, dayclose, dayvol) select begintime, bankuaicode, dayopen, dayhigh, daylow, dayclose, dayvol from lsbankuaidata where bankuaicode=' + @ bankuaicode + 'and begintime=' + @ begintime1 + '
The exec (@ SQL)
set @ sql1='select @ sum5=sum (t.d ayclose) from (select top 5 dayclose from' + @ bankuainame + where begintime='+ @ begintime1 +' order by begintime desc) t '
The exec sp_executesql @ sql1, N '@ sum5 float', @ sum5
Set @ sql2='update' + + 'set day5=' + @ @ bankuainame sum5 + 'where begintime=' + @ begintime1 + '
The exec (@ sql2)
end
CodePudding user response:
/*
First you @ sum5 is a float, you talk to string together, not conversion, this newspaper nvarchar converted to float error
Second, your query without the quotes, you will see is printed like this:
The SELECT begintime, bankuaicode dayopen dayhigh, daylow, dayclose, dayvol from lsbankuaidata where bankuaicode=value and begintime=2020-11-12
Again, your bankuaicode and begintime two conditions directly and without a space here
Again, few @ sum5 calculation, you sp_executesql did not use the output, so you are not the calculation result of string inside
*/
The ALTER PROC [dbo] [addbktodaydata1]
@ bankuaicode VARCHAR (50)
AS
The BEGIN
DECLARE @ SQL NVARCHAR (1000)
DECLARE @ sql1 NVARCHAR (1000)
DECLARE @ sql2 NVARCHAR (1000)
DECLARE @ bankuainame NVARCHAR (100)
DECLARE @ begintime1 NVARCHAR (20)
DECLARE @ sum5 float
The SET @ begintime1=the CONVERT (VARCHAR (10), GETDATE (), 120)
The SET @ bankuainame='zhy + @ bankuaicode
SQL="insert into the SET @ + @ bankuainame + '(begintime, bankuaicode dayopen, dayhigh, daylow, dayclose, dayvol)
The select begintime, bankuaicode dayopen dayhigh, daylow, dayclose, dayvol
The from lsbankuaidata where bankuaicode=@ bankuaicode and begintime
=@ begintime1 'The EXEC sp_executesql @ SQL, N '@ bankuaicode VARCHAR (50), @ begintime1, NVARCHAR (20)', @ bankuaicode, @ begintime1
The SET @ sql1='select @ sum5=sum (t.d ayclose) from (select top 5 dayclose from' + @ bankuainame + where begintime=@ begintime1 order by begintime desc) t '
The exec sp_executesql @ sql1, N '@ begintime1 NVARCHAR (20), @ sum5 float the output', @ begintime1, @ sum5 output
='update' SET @ sql2 + @ bankuainame + 'SET day5=@ sum5 where begintime=@ begintime1'
The exec sp_executesql @ sql2, N '@ begintime1 NVARCHAR (20), @ sum5 float', @ begintime1, @ sum5
END
CodePudding user response:
-- I insert, update tables and also less a space before the set
The ALTER PROC [dbo] [addbktodaydata1]
@ bankuaicode VARCHAR (50)
AS
The BEGIN
DECLARE @ SQL NVARCHAR (1000)
DECLARE @ sql1 NVARCHAR (1000)
DECLARE @ sql2 NVARCHAR (1000)
DECLARE @ bankuainame NVARCHAR (100)
DECLARE @ begintime1 NVARCHAR (20)
DECLARE @ sum5 float
The SET @ begintime1=the CONVERT (VARCHAR (10), GETDATE (), 120)
The SET @ bankuainame='zhy + @ bankuaicode
SQL="insert into the SET @ + @ bankuainame + '(begintime, bankuaicode dayopen, dayhigh, daylow, dayclose, dayvol)
The select begintime, bankuaicode dayopen dayhigh, daylow, dayclose, dayvol
The from lsbankuaidata where bankuaicode=@ bankuaicode and begintime
=@ begintime1 'The EXEC sp_executesql @ SQL, N '@ bankuaicode VARCHAR (50), @ begintime1, NVARCHAR (20)', @ bankuaicode, @ begintime1
The SET @ sql1='select @ sum5=sum (t.d ayclose) from (select top 5 dayclose from' + @ bankuainame + where begintime=@ begintime1 order by begintime desc) t '
The exec sp_executesql @ sql1, N '@ begintime1 NVARCHAR (20), @ sum5 float the output', @ begintime1, @ sum5 output
='update' SET @ sql2 + @ bankuainame + 'SET day5=@ sum5 where begintime=@ begintime1'
The exec sp_executesql @ sql2, N '@ begintime1 NVARCHAR (20), @ sum5 float', @ begintime1, @ sum5
END