If conditions for stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murthychvrm
    New Member
    • Apr 2008
    • 3

    If conditions for stored procedure

    i wrote the stored procedure like as below .it was executed successfully.no w i want to write if conditions for this stored procedure at check all conditions if i give fromdate and todate this is first case.second is not give fromdate and give todate.third give fromdate and not give todate.if i not give fromdate and not give todate.
    how to write code for above cases?

    stored procedure:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    go
    alter PROCEDURE [dbo].[sp_selectgunnie itemtran]
    (@fromdate datetime,@todat e datetime)
    --(@fromdate datetime,@todat e datetime,@Date datetime,@Issue _No int,@Item_Desc varchar(50),@Qu antity int,@Agent_name varchar(50),@Ag ent_Code int)
    AS
    BEGIN
    select
    riq.Issue_No,ri q.Item_Desc ,riq.Quantity ,ri.Date,
    a.Agent_name,a. Agent_Code
    from
    Rice_Agent_Mast er a,Rice_Issues ri,Rice_Issues_ Qty riq

    where
    ri.Date between @fromdate and @todate
    and
    riq.Agent_Code= a.Agent_Code
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    check all conditions if i give fromdate and todate this is first case.second is not give fromdate and give todate.third give fromdate and not give todate.if i not give fromdate and not give todate.
    how to write code for above cases
    It is roughly
    Code:
    CASE WHEN (fromdate IS NULL AND todate IS NULL) THEN fault 
    ELSE fromdate IS NULL THEN second
    ELSE todate IS NULL THEN third
    ELSE first
    Apologies if syntax is wrong

    Comment

    Working...