Select syntax error

  • declare @sequence_number int

    set @sequence_number = select case when workflow_activity_type_identifier = 197 then '1'

    else

    case when workflow_activity_type_identifier = 203 then '1'

    else(select count(*) from workflow_activity where workflow_activity_type_identifier in (200,201)

    and workflow_activity_identifier = @workflow_activity_identifier

    and workflow_identifier=@workflow_identifier)

    end

    end

    from workflow_activity

    I m getting ERROR : Incorrect syntax near the keyword 'select'.

    what is that error?

    thanks.

  • Drop the SET and do the assignment as part of the select

    declare @sequence_number int

    select @sequence_number =

    case

    when workflow_activity_type_identifier = 197 then '1'

    else

    case when workflow_activity_type_identifier = 203 then '1'

    else(select count(*)

    from workflow_activity

    where workflow_activity_type_identifier in (200,201)

    and workflow_activity_identifier = @workflow_activity_identifier

    and workflow_identifier=@workflow_identifier)

    end

    end

    from workflow_activity

    Just be warned, if there's more than 1 row in the workflow_activity table, it's not easy to say which row will be the one evaluated for the variable.

    What, exactly, are you trying to do with this statement?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • you

  • Thanks for early reply,

    if there is more than one row in workflow_activity table.

    what changes can i do in the code?

    Thanks.

  • What exactly are you trying to do with that code? Only then, we can help you re-write that code correctly.

    --Ramesh


  • i created stored procedure fro migrating the data from one sqlserver databse another sqlserver database.

    My task is ther is workflow of xxxxxx.

    i have to display sequence no increments based on the no of times the borrower completed the task(activity).

    i have different task no's like 1,2,3,4

    Here 1 and 2 tasks should do one time,the 3 and 4 can repeat multiple times.

    this is the req.

    i written the query in my post.

    thanks,

  • Can you explain in a bit more detail please. Maybe with some sample data and desired results.

    Read this to see the best way to post this to get quick responses.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

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