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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Calling sproc within a select statement

Author  Topic 

rinakrugm
Starting Member

2 Posts

Posted - 2003-05-19 : 16:15:51
I would greatly appreciate any feedback.
Is there a way to call a sproc within a select statement, the same way built-in functions are called?
For instance, you can say

select productName, convert(varchar(15), sellerName), price, condition from productInfo

Let's say I need to convert the sellerName in a more complicated way and I wrote a stored procedure to do it.

i.e.
create convertSellerName @name varchar(35) as
..... convert code......
go

or maybe it needs an output parameter (?),

create convertSellerName @name varchar(35), @new_name varchar(15)output as
...

How do I call it within the select statemt? I can't figure it out.

Thanks,
Rina.


Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2003-05-19 : 16:22:40
Why don't you write it as a User Defined Function instead? Almost the same as a SPROC but you can call UDF's within a SELECT statement. There are some limits though.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-05-19 : 16:24:39
You can not call a stored procedure in a select statement. You will have to first call the stored procedure to get the output then use the output in your select statement.

Why don't you just use user-defined functions to do this? Or are you using SQL 7.0 or lower?

Tara
Go to Top of Page

rinakrugm
Starting Member

2 Posts

Posted - 2003-05-19 : 17:38:06
quote:

You can not call a stored procedure in a select statement. You will have to first call the stored procedure to get the output then use the output in your select statement.

Why don't you just use user-defined functions to do this? Or are you using SQL 7.0 or lower?

Tara



Thanks a lot, very unfortunately I can't create UDF's, so I just used a long chain of built-in functions within the select.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-05-19 : 17:42:37
quote:

Thanks a lot, very unfortunately I can't create UDF's, so I just used a long chain of built-in functions within the select.



But why can't you create UDFs? Won't a long chain of built-in functoins within the select be slower than calling the stored procedure first then the select? I would test both scenarios for performance. You might find that by doing it in one select without a UDF is going to give you bad performance.

Tara
Go to Top of Page
   

- Advertisement -