Click here to Skip to main content
15,899,586 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
CREATE PROCEDURE [dbo].[K_FS_Test] 
	
	@fromdate datetime,
    @todate	 datetime,
    @customertype varchar(50),
    @customername varchar(50)
	
AS
if(select Orderno from k_Fs_orderdetails where attrited = 'false')

BEGIN
      	
	
	SET NOCOUNT ON;
select orderno from K_FS_OrderDetails where attrited = 'false' AND customertype in (@customertype) and customername in (@customername)
 and ordereddate between @fromdate and @todate
order by orderno desc 
   
END
ELSE	
	BEGIN
	
	select orderno from K_FS_OrderDetails where attrited = 'TRUE' AND customertype in (@customertype) and customername in (@customername)
 and ordereddate between @fromdate and @todate
order by orderno desc 
   
   END


Please correct this procedure...
Posted
Updated 11-Mar-14 21:40pm
v3
Comments
RAHUL(10217975) 12-Mar-14 3:52am    
Can u provide table structure with data? and what error you are facing?

if orderno='love'

SQL
if((select Orderno from k_Fs_orderdetails where attrited = 'false')='love')
 
Share this answer
 
Always include the error message in your question to get quick answers.

IIRC you should use the condition like below(IF EXISTS)
SQL
IF EXISTS(select Orderno from k_Fs_orderdetails where attrited = 'false')

Check this one for simple example
Drop Stored Procedure if exist in SQL Server[^]

OR get the value(first SELECT query result) in a variable, use IF condition for that to create conditions

And careful with case sesitive things. Yes, why are you using 'false' & 'TRUE'. Use either lowercase or UPPERCASE for both values. I recommend you to use functions UPPER/LOWER in your query to get right resultset.
 
Share this answer
 
Comments
Siva Hyderabad 12-Mar-14 4:53am    
thanks thatraja
thatraja 12-Mar-14 5:04am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900