Solved

Returning rows with a stored procedure

Posted on 2012-03-22
3
184 Views
Last Modified: 2012-03-29
Hi

I hope somebody can help me with the following.

I need to retrieve some records using a SELECT but also using a stored procedure.

Suppose the table (myTable) I have has the following format:

ID      NAME     DOB     SCORE

I have a stored procedure myStoredProcedure(NAME, X, Y, Z)

where NAME and SCORE are values passed in and X, Y and Z are returned values.

This is the pseudo code I'm trying to do

SELECT * FROM myTable WHERE myTable.SCORE = X "using" myStoredProcedure(myTable.NAME, X, Y, Z)

where X is an output parameter from the stored procedure using values from myTable.

Can anybody help?

Thanks in advance

John
0
Comment
Question by:IssacJones
[X]
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
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 300 total points
ID: 37752281
Create a user defined scalar function to do the same work myStoredProcedure and return the required value

CREATE FUNCTION ......

Then
SELECT * FROM myTable WHERE myTable.SCORE = dbo.udfYourFunction(NAME, X, Y, Z)
0
 
LVL 17

Expert Comment

by:Barry Cunney
ID: 37752284
The function will have just return a single value - Why are you returning 3 different values - What is the business logic?
May have to look at using a table valued function and cross apply
0
 

Author Comment

by:IssacJones
ID: 37752639
the 3 different values are used in other cases. I'll try your first idea.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

688 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