Re: Syntax error in stored procedure

  • Hi everyone,

    I'm having trouble w/ the sproc.  Could someone take a look?

    Thanks much!

    Error 156:Incorrect syntax near the keyword ‘SELECT’.

    Incorrect syntax near the keyword ‘FOR’.

    CREATE PROCEDURE spGet_email_list

     @sampling_data_id int,

     @email_type int OUT

    AS

    declare @CT as int, @deflash as bit, @belt_sort as bit, @lot_deviation as bit, @email_one as int, @email_two as int, @email_three as int

    declare get_email_id  cursor

    SELECT     @CT = count(dbo.tblBag_results.bag_results_id)

    FROM         dbo.tblBag_results INNER JOIN

                          dbo.tblSampling_data ON dbo.tblBag_results.sampling_data_id = dbo.tblSampling_data.sampling_data_id

    WHERE     (dbo.tblBag_results.sampling_data_id =@sampling_data_id) AND (dbo.tblBag_results.bag_result = 2)

    if @CT > 0

    --Begin

    For

    SELECT dbo.tblBag_results.deflash, dbo.tblBag_results.belt_sort, dbo.tblSampling_data.lot_deviation

    FROM         dbo.tblBag_results INNER JOIN

                         dbo.tblSampling_data ON dbo.tblBag_results.sampling_data_id = dbo.tblSampling_data.sampling_data_id

    Open get_email_id

    Fetch Next FROM get_email_id INTO @deflash, @belt_sort, @lot_deviation

    While @@Fetch_status = 0

     Begin

     if @deflash =1 AND @email_one <> 1

     set @email_one = 1

     set @email_type = @email_type & "1"

     if @belt_sort = 1 AND @email_two <> 1

     set @email_two = 1

     set @email_type = @email_type & "2"

     if @lot_deviation = 1 AND @email_three <> 1

     set @email_three = 1

     set @email_type = @email_type & "3"

     Fetch Next FROM get_email_id INTO @deflash, @belt_sort, @lot_deviation  

     end

     

    close get_email_id

    deallocate get_email_id

    --end

    GO

  • You are missing the FOR keyword on your cursor declaration:

    declare get_email_id  cursor FOR Select ....

     

  • Yep, That's the problem. Thanks PW!

     

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply