?
Solved

Returning rows with a stored procedure

Posted on 2012-03-22
3
Medium Priority
?
185 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 1200 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

777 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