optional parameter in select query

  • hi

    i have a situation in stored procedure where i get partial parameter so i have to use select query with like option but with parameter i will have to execute it in a string but when i execute it i get following error

    Server: Msg 403, Level 16, State 1, Line 4

    Invalid operator for data type. Operator equals modulo, type equals varchar.

    My query is

    CREATE PROC CM_SP_SelFireDistrictCode @fdt_v_firecode varchar(15)='OPT'--optional

    As

    declare @err int

    declare @sstring varchar(500)

    if @fdt_v_firecode ='OPT' --optional

    Begin

    select FDT_V_FIRECODE,FDT_V_DESC,FDT_V_COUNTY from ZCM_FDT_FIREDISTRICT

    End

    Else

    @sstring='select FDT_V_FIRECODE,FDT_V_DESC,FDT_V_COUNTY from ZCM_FDT_FIREDISTRICT where FDT_V_FIRECODE like '%@fdt_v_firecode%''

    print @sstring

    exec @sstring

    End

    set @err =@@error

    if @err<>0

    return  @err

    GO

  • select @sstring='select FDT_V_FIRECODE,FDT_V_DESC,FDT_V_COUNTY from ZCM_FDT_FIREDISTRICT where FDT_V_FIRECODE like ''%'+@fdt_v_firecode+'%'''

  • Thanks WZ700 it works

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

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