If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > HELP! Stored Procedure problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-03, 07:57
GA_KEN GA_KEN is offline
Registered User
 
Join Date: Jan 2003
Posts: 126
Unhappy HELP! Stored Procedure problem

I have the following stored procedure:

Code:
CREATE procedure sp_BA_BuildTablesStep2

(
@BACKENDDATEVALUE varchar(10),
@QUERYSTATMENT varchar(100)
)

AS

DECLARE @SQL varchar(8000)
SET @SQL = " if object_id('BA_BACK') is not null drop table BA_BACK

	SELECT 	BA_NEW.SRC_CODE, 
			Count(RG_BA_SHIPPED_ORDERS.ORDER_NBR) AS SUBSEQUENT_ORDERS, 
			Sum(RG_BA_SHIPPED_ORDERS.TOTAL_AMT) AS INVOICE_TOTAL, 
			Sum(RG_BA_SHIPPED_ORDERS.SHIP_CHARGE) AS SHIPPING_CHARGE, 
			Sum(RG_BA_SHIPPED_ORDERS.SHIP_COST) AS SHIPPING_COST, 
			Sum(RG_BA_SHIPPED_ORDERS.MARGIN) AS MARGIN 
	
	INTO 		BA_BACK
	
	FROM 		BA_NEW INNER JOIN RG_BA_SHIPPED_ORDERS ON BA_NEW.CUST_NBR = RG_BA_SHIPPED_ORDERS.CUST_NBR
	
	WHERE 	(RG_BA_SHIPPED_ORDERS.DATE > [BA_NEW].[MaxOFDATE]) And (RG_BA_SHIPPED_ORDERS.DATE < = " + @BACKENDDATEVALUE+ ")  " + @QUERYSTATMENT +"
	
	GROUP BY 	BA_NEW.SRC_CODE"

EXEC(@SQL)

GO
When I run it I get 0 rows affected, when I run the query in QA with my values plugged in I get the results I want... can you see anything I did wrong?

@BACKENDDATEVALUE is a date supplied as '02/18/03' and @QUERYSTATMENT is like: 'and RG_BA_SHIPPED_ORDERS.CO_TYPE =1'

I'm changeing @QUERYSTATMENT by adding "OR" statements at the end depending on what the user chooses in the form.

Any ideas???

Ken
Reply With Quote
  #2 (permalink)  
Old 02-17-03, 08:32
GA_KEN GA_KEN is offline
Registered User
 
Join Date: Jan 2003
Posts: 126
Talking

Figured out the problem! I wasn't passing the vars correctly!

Thanks much!

Ken
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On