By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,378 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,378 IT Pros & Developers. It's quick & easy.

If conditions for stored procedure

P: 3
i wrote the stored procedure like as below .it was executed successfully.now 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_IDENTIFIER ON
go
alter PROCEDURE [dbo].[sp_selectgunnieitemtran]
(@fromdate datetime,@todate datetime)
--(@fromdate datetime,@todate datetime,@Date datetime,@Issue_No int,@Item_Desc varchar(50),@Quantity int,@Agent_name varchar(50),@Agent_Code int)
AS
BEGIN
select
riq.Issue_No,riq.Item_Desc ,riq.Quantity ,ri.Date,
a.Agent_name,a.Agent_Code
from
Rice_Agent_Master a,Rice_Issues ri,Rice_Issues_Qty riq

where
ri.Date between @fromdate and @todate
and
riq.Agent_Code=a.Agent_Code
Jun 4 '08 #1
Share this Question
Share on Google+
1 Reply


code green
Expert 100+
P: 1,726
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
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN (fromdate IS NULL AND todate IS NULL) THEN fault 
  2. ELSE fromdate IS NULL THEN second
  3. ELSE todate IS NULL THEN third
  4. ELSE first
Apologies if syntax is wrong
Jun 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.