Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

T-SQL: select from array list parameter and return multiple results

Posted on 2014-02-25
3
778 Views
Last Modified: 2014-07-29
Hello, I am trying to parse a array of ID's and then return the results:
ALTER PROCEDURE dxf1s_qqq.Getup_GetFriends
-- Add the parameters for the stored procedure here
 @FriendListID varchar(max),
 @FacebookID bigint OUTPUT,
 @CurrentL float OUTPUT,
 @CurrentP float OUTPUT,
 @CurrentU int OUTPUT,
 @Created datetime OUTPUT
AS
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN
SELECT @FacebookID = FacebookID, @CurrentL = CurrentL, @CurrentP = CurrentP, @CurrentU = CurrentU, @Created = Created FROM Getup_Log.SplitInts(@FriendListID, ',');
RETURN
END

Open in new window

When I execute it:
Running [dxf1s_qqq].[Getup_GetFriends] ( @FriendListID = 3391443009,3391443008, @FacebookID = <DEFAULT>, @CurrentL = <DEFAULT>, @CurrentP = <DEFAULT>, @CurrentU = <DEFAULT>, @Created = <DEFAULT> ).
Procedure or function 'Getup_GetFriends' expects parameter '@FacebookID', which was not supplied.
No rows affected.
(0 row(s) returned)
@FacebookID = <NULL>
@CurrentL = <NULL>
@CurrentP = <NULL>
@CurrentU = <NULL>
@Created = <NULL>
@RETURN_VALUE = 
Finished running [dxf1s_qqq].[Getup_GetFriends].

Open in new window

I get null when I execute it, and I do have a data inside my table with these two FacebookID's
The table looks like this:
ID - int (auto identifyer)
FacebookID - bigint
CurrentL - float
CurrentP - float
CurrentU - int
Created - datetime
0
Comment
Question by:JoachimPetersen
3 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39887764
When you execute the Stored Procedure you need to define all the parameters as OUTPUT parameters.  If this is not clear, show us how you are executing the Stored Procedure and we can correct it.

Incidentally, this Stored Procedure does not return a result set.
0
 

Author Comment

by:JoachimPetersen
ID: 39888150
I execute the stored procedure with Visual Studio Server Explorer (same as SQL management), I only parse the FriendListID array and I set the rest of the values as OUTPUT, do you want me to set the FriendListID as OUTPUT too?
Changing the @FriendListID varchar(max) to @FriendListID varchar(max) OUTPUT did not help, now it just simply only retruns the @FriendListID, the rest of the parameters is not returned.

what I want is simply: parse an array of ID's, select specific fields where the ID's match and retrun it somehow where I can simply manage the return values in asp.net / vb.net

A working example where you parse an array of ID's, select specific fields where the ID's match and retrun the values (the retrun value should be asp .net/ vb.net friendly), I can rewrite it to suit my needs myself.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39966179
in your procedure, you cannot do a SELECT to return several records together with setting OUTPUT parameters.

so, I presume your stored procedure shall be rather something like this: 1 single input paramter:
ALTER PROCEDURE dxf1s_qqq.Getup_GetFriends
-- Add the parameters for the stored procedure here
 @FriendListID varchar(max)
AS
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN
SELECT t.FacebookID, t.CurrentL, t.CurrentP, t.CurrentU, t.Created 
FROM Getup_Log.SplitInts(@FriendListID, ',') fn
JOIN sometable t ON t.ID = fn.value_column_please_put_the_correct_name_here_instead;
RETURN
END

Open in new window

       
and in your calling code, you just define and pass that first parameter, the results are coming back as DataReader or Dataset, depending on you actually call it in the end
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question