4

以下の書かれた手順を実行すると、以下のエラーが発生します。これで何がうまくいかないのですか?

エラー :

メッセージ 156、レベル 15、状態 1、手順 tbv21Setup、行 11 キーワード「VIEW」付近の構文が正しくありません。

**

CREATE PROCEDURE tbv21Setup

AS
BEGIN

    CREATE VIEW Cust_Address_View AS
        SELECT customer.individual_id   individual_id,
          customer.tb_customer_id   customer_id,
          customer.customer_category_lkp    customer_category_lkp,
          ADDRESS.postal_code   postal_code
        FROM CUSTOMER
        INNER JOIN INDIVIDUAL
        ON (CUSTOMER.individual_id = INDIVIDUAL.individual_id)
        JOIN
          (SELECT address_id ,
            a.individual_id ,
            postal_code ,
            obsolete_flag ,
            tb_modified_date
          FROM address a
          INNER JOIN
            (SELECT individual_id,
              MAX(ISNULL((tb_modified_date),('01/01/1900'))) AS max_tb_modified_date
            FROM ADDRESS
            WHERE obsolete_flag = 0
            GROUP BY individual_id
            ) AS xa
          ON (xa.individual_id                   = a.individual_id
          AND xa.max_tb_modified_date            = ISNULL((a.tb_modified_date),('01/01/1900')))
          WHERE a.obsolete_flag                  = 0
          ) AS ADDRESS ON (ADDRESS.individual_id = INDIVIDUAL.individual_id)
        AND customer.customer_category_lkp       =
          (SELECT lookup_id
          FROM lookup
          WHERE lookup_category_name = 'customer_category'
          AND code_string            ='prospect'
          )
        AND customer.obsolete_flag   =0
        AND ADDRESS.postal_code NOT IN ('UNKNOWN','unknown','U','u',' ','');

    ALTER TABLE tb_customer_attribute 
    ADD  tb_customer_attribute_id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
                obsolete_flag int,
                revision_number int;

    CREATE TABLE tb_comm_hist_xfer (
        tb_comm_hist_xfer_id binary(16) NOT NULL,
        tb_old_customer_id int NOT NULL,
        tb_customer_id int NULL,
        date_entered datetime NOT NULL
    );


    --Logger table
    CREATE TABLE TBLogger (logDate DATETIME, logSQL VARCHAR(MAX), logRows INT, errKode INT);

    --Create a parameter table in CRB/STAGE database which will hold a row for crb/stage db prefix.
    CREATE TABLE crb_parameter (stgdb_prefix VARCHAR(255));

    INSERT INTO crb_parameter values ('tommydev1.dbo');
    --uncomment the below line and comment the above line in PRODUCTION
    --INSERT INTO crb_parameter values ('tb_stage.dbo');


END
4

3 に答える 3

1

ヒント: ストア プロシージャを使用する代わりに、ビューを直接作成します。

ストア プロシージャを使用してビューを作成する

于 2013-04-24T06:50:10.707 に答える