web-dev-qa-db-ja.com

SQLServerでSELECTNEXT VALUEを機能させる方法は?

SQLServerで次のものを機能させるのに問題があります。

CREATE TABLE table_X AS
    SELECT 
        NEXT VALUE FOR GROUP_A AS GROUP_ID, RISK_ID
    FROM 
        ( SELECT UNIQUE RISK_ID, FROM table_Y ) SS;

私は言われた:

"Incorrect syntax near the keyword 'SELECT'."
"Incorrect syntax near the keyword 'UNIQUE'."

問題は正確には何ですか?これをSQL Serverで機能するように修正するにはどうすればよいですか?

7
Alex
CREATE TABLE Person
(
FirstName Varchar(50),
LastName Varchar(50)
);

/*
Insert Some Values Into Person
*/

CREATE SEQUENCE CountBy
    START WITH 1
    INCREMENT BY 1 ;

SELECT NEXT VALUE FOR CountBy OVER (ORDER BY LastName) AS ListNumber,
    FirstName, LastName
    INTO table_x
FROM Person
16
Sridhar
SELECT 
    NEXT VALUE FOR GROUP_A AS GROUP_ID, SS.RISK_ID
INTO
    table_X 
FROM 
    ( SELECT DISTINCT RISK_ID FROM table_Y ) SS
2
Secret Squirrel

これを試してください-

IF OBJECT_ID ('dbo.table_X') IS NOT NULL
   DROP TABLE dbo.table_X

SELECT RISK_ID --, ..... columns
INTO dbo.table_X
FROM ( 
    SELECT DISTINCT RISK_ID 
    FROM dbo.table_Y 
) SS

SELECT * 
FROM dbo.table_X
1
Devart