Help for Sql Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • majidsql
    New Member
    • Nov 2006
    • 1

    Help for Sql Query

    I am writing one procedure and in that i am giving three inputs ie account number and from date and to date, and i will give any one inupt ie account number or (from and to dates).

    So in the procedure i want to select records from table and in where condition depending on input ie account number or from and to dates, so i am not able to write query,

    I will write the query here what i know, please corrct the query bcoz i am getting error

    Select
    *
    From Mf_Tran_Reg
    Where
    mft_fundcd='ABN ' and mft_purred='P'
    if @Folio = '' --if account number is null
    begin
    and mft_procdate between @Fdate and @tdate
    end
    else
    begin
    and mft_accno= @Folio
    end
  • jf951
    New Member
    • Nov 2006
    • 2

    #2
    do the conditional branching earlier,

    if @Folio = '' --if account number is null

    select * from tbl where param1 and param2 and param3

    else

    select * from tbl where param2 and param3


    Originally posted by majidsql
    I am writing one procedure and in that i am giving three inputs ie account number and from date and to date, and i will give any one inupt ie account number or (from and to dates).

    So in the procedure i want to select records from table and in where condition depending on input ie account number or from and to dates, so i am not able to write query,

    I will write the query here what i know, please corrct the query bcoz i am getting error

    Select
    *
    From Mf_Tran_Reg
    Where
    mft_fundcd='ABN ' and mft_purred='P'
    if @Folio = '' --if account number is null
    begin
    and mft_procdate between @Fdate and @tdate
    end
    else
    begin
    and mft_accno= @Folio
    end

    Comment

    Working...