我在将数据插入现有SQL Server表时遇到问题。
IF OBJECT_ID('Coinmarketcap.dbo.tbl_ATR', 'U') IS NOT NULL
DROP TABLE Coinmarketcap.dbo.tbl_ATR;
SELECT
[Ticker],[Date],[px_high], [px_low], [px_close],[yest_close],
ATR_spd = iif([px_high] > yest_close, [px_high], yest_close) - iif([px_low] > yest_close, yest_close, [px_low]),
ATR1 = (iif([px_high] > yest_close, [px_high], yest_close) - iif([px_low] > yest_close, yest_close, [px_low])) / (iif(yest_close = 0 , 1 , yest_close))
FROM
(SELECT
*, yest_close = lag([px_close]) OVER (PARTITION BY Ticker ORDER BY [Date])
FROM
[Coinmarketcap].[dbo].[daily_data]) t
INTO
[Coinmarketcap].[dbo].[tbl_ATR]
ORDER BY
[Ticker] ASC, [Date] DESC
我无法确定INTO
语句的放置位置。
关键字' INTO'。
附近的语法不正确
还尝试INSERT INTO
声明无济于事。
答案 0 :(得分:1)
稍微关闭......并且您不需要订单,因为您丢弃了表并且它被存储为无序集(因为您没有在此处应用索引)。我假设你想从结果中继承定义。这是使用SELECT ... INTO TABLE ... FROM TABLE
而不是INSERT INTO TABLE ... SELECT ... FROM TABLE
IF OBJECT_ID('Coinmarketcap.dbo.tbl_ATR', 'U') IS NOT NULL
DROP TABLE Coinmarketcap.dbo.tbl_ATR;
SELECT
[Ticker],
[Date],
[px_high],
[px_low],
[px_close],
[yest_close],
ATR_spd = iif([px_high] > yest_close, [px_high], yest_close) - iif([px_low] > yest_close, yest_close, [px_low]),
ATR1 = (iif([px_high] > yest_close, [px_high], yest_close) - iif([px_low] > yest_close, yest_close, [px_low])) / (iif(yest_close = 0 , 1 , yest_close))
INTO [Coinmarketcap].[dbo].[tbl_ATR]
FROM (
SELECT
*,
yest_close = lag([px_close]) OVER (PARTITION BY Ticker ORDER BY [Date])
FROM [Coinmarketcap].[dbo].[daily_data]
) t
注意,你做不到......
INSERT INTO TABLE
SELECT FROM SomeTable
首先没有明确创建该表。我使用上面的SELECT INTO
,因为你在声明之前删除了表。