Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 1st, 2005, 06:45 PM
GEM1204 GEM1204 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Texas
Posts: 169 GEM1204 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 36 m 57 sec
Reputation Power: 5
Sp Parameters using 'In()'

I have a MS Access projects database that’s linked to an Sql Server database. I want to base my reports on stored procedures that have parameters. How would I pass an ‘in’ statement to my parameter so that instead of @Location = ‘Dallas’ I could do something like an in statement @Location in (‘Dallas’,’Chicago’,’Seattle’). I know that if I used a view I could just pass a filter. How can I accomplish the same thing with a sp and parameters? I know there has to be a way to do this but I can't figure it out



Thanks

Reply With Quote
  #2  
Old April 2nd, 2005, 03:38 AM
yogaboy yogaboy is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: Near London
Posts: 112 yogaboy User rank is Corporal (100 - 500 Reputation Level)yogaboy User rank is Corporal (100 - 500 Reputation Level)yogaboy User rank is Corporal (100 - 500 Reputation Level)yogaboy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 14 h 37 m 29 sec
Reputation Power: 5
I use this function I got from somewhere on the net, I know it's called SplitOrderIDs but it will work for any varchar like '37,38,39' etc

Code:
CREATE FUNCTION dbo.SplitOrderIDs
(
	@OrderList varchar(500)
)
RETURNS 
@ParsedList table
(
	OrderID int
)
AS
BEGIN
	DECLARE @OrderID varchar(10), @Pos int

	SET @OrderList = LTRIM(RTRIM(@OrderList))+ ','
	SET @Pos = CHARINDEX(',', @OrderList, 1)

	IF REPLACE(@OrderList, ',', '') <> ''
	BEGIN
		WHILE @Pos > 0
		BEGIN
			SET @OrderID = LTRIM(RTRIM(LEFT(@OrderList, @Pos - 1)))
			IF @OrderID <> ''
			BEGIN
				INSERT INTO @ParsedList (OrderID) 
				VALUES (CAST(@OrderID AS int)) --Use Appropriate conversion
			END
			SET @OrderList = RIGHT(@OrderList, LEN(@OrderList) - @Pos)
			SET @Pos = CHARINDEX(',', @OrderList, 1)

		END
	END	
	RETURN
END


and here is an example of a procedure I use to update a table, using the function from above
Code:
CREATE PROC dbo.uspUpdatePJWithInvoiceNo
(
@NewInvoiceNumber int,
@OrderList varchar(500)
)

AS
	UPDATE Personal_Journal
	SET InvoiceNumber = @NewInvoiceNumber
	WHERE [ID] IN (
	 SELECT * FROM dbo.SplitOrderIDs(@OrderList)
			)


Hope this helps
Iain

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Sp Parameters using 'In()'


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT