Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Returning a value from stored proc with query

Author  Topic 

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2014-07-18 : 03:19:38
Hi

In some of our business object reports we have to create variables to decode values to what we want. I am trying to replicate this in SQL Server and remember doing this in SQL server 2000 years ago back can't remember the exact way to do it.

I remember running a query and calling stored proc within query which would return the value I wanted but not sure if I can still do this in SQL server 2008 and by that I mean doing it within query or have to do it another way.

Basically what I want is to have a procedure with all the variables replicated within that procedure so that when I run a query I can just call the appropriate bit of code by passing a specific name like

select job.dept, dbo.decodevariable('ShowJobDesc' job.jobtitle), job.salary
from job

so 'ShowJobDesc' and the job.jobtitle would be used to decode each job title to return job description.

Just a bit unsure and can't remember if I am doing this the right way, is this possible?

Many Thanks for any help/advice

G

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2014-07-18 : 03:31:13
Actually just remembered it was User Defined Function I used to use!

Which can be called in query.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2014-07-19 : 02:41:16
If you want to return data from a UDF and it is a multiple rows , use a table variable - http://www.sqlserver-dba.com/2011/12/sql-table-variable-and-temporary-table.html

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -