0
CREATE SEQUENCE id AS INTEGER START WITH 1 INCREMENT BY 1;
WITH source (Id, SomeColumn) AS
(
SELECT NEXT VALUE FOR id, 'some value 1'
UNION
SELECT NEXT VALUE FOR id, 'some value 2'
)
SELECT * FROM source;
DROP SEQUENCE id;
它引發以下錯誤:SQL Server將選擇
NEXT VALUE FOR function is not allowed in check constraints, default objects, computed columns, views, user-defined functions, user-defined aggregates, user-defined table types, sub-queries, common table expressions, derived tables or return statements.
爲什麼NEXT VALUE FOR
功能不能與unions
工作? 什麼是好的選擇?
我正在使用類似的CTE使用合併語句爲默認值的表建立種子。我試圖避免手動鍵入一系列數字。
我需要這樣的東西UNION SELECT ID ++
這是如何「不工作」?請提供詳細信息。 –
您是否考慮過ROW_NUMBER()窗口函數?你是否在尋找這樣的東西:http://stackoverflow.com/questions/37287657/sql-server-2012-create-a-new-table-with-instant-1000-record-that-contains-thre/37288556# 37288556? – Alex
這種老式的解決方案適合你嗎? CREATE TABLE#時(ID INT IDENTITY(1,1),someValue中VARCHAR(255)) INSERT INTO#時(someValue中) SELECT '一些值1' AS someValue中 UNION SELECT '一些值2' SELECT * FROM #h H –