以下代码:
declare @tradeDate date = select tradeDate from tSystemStatus
生成错误:
Incorrect syntax near the keyword 'select'.
表格结构:
CREATE TABLE [dbo].[tSystemStatus](
....
[TradeDate] [date] NOT NULL,
....
我错了什么?
答案 0 :(得分:2)
试试这个
declare @tradeDate date = (select tradeDate from tSystemStatus)
但是如果select查询返回的值多一个,那么它会抛出错误(你可以在这里使用top 1)
declare @tradeDate date = (select top 1 tradeDate from tSystemStatus)
或者
declare @tradeDate date
select @tradeDate = tradeDate from tSystemStatus
答案 1 :(得分:1)
试试这个
declare @tradeDate date;
select @tradeDate=tradeDate from tSystemStatus