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
 Execute user defined function in select statement

Author  Topic 

extrapulp
Starting Member

9 Posts

Posted - 2010-06-17 : 16:29:27
I do not know if this is even possible.

I have a stored procedure, and a user defined function that I created. I would like to call the function from within the procedure in a select statement using the output from the function to create a row in the results.

Here is the stored procedure.
Select PartNum, Min, Max, Available, SalesSample, PendingSale, Notes 
From dbo.DomeStock


That works just fine. What I would like it to be is something like this.
Select PartNum, Min, Max, Available, SalesSample, PendingSale, Notes, execute 'sort' =GetTripForce PartNum 
From dbo.DomeStock


I am trying to get the results from the function GetTripForce to show up in a column named 'sort'.

I have debugged the function and it reliably returns the number I am looking for from the data. I just dont know how to apply the results of the function to the data that is returned.

The end result I am looking for is to use the data returned from the function as a sorting mechanism. Currently I am ordering by the PartNum which is alphanumeric. The order in which it sorts is not what the end user wants.

Here is some sample data the way it sorts at the moment.
PartNum
F06085
F06085N
F08240
F10340N
FD06085
FD06085N

The desired results with the same data would be
PartNum
F06085
F06085N
FD06085
FD06085N
F08240
F10340N

The sort should be first on the preceding letters (there can be up to four), the second sort should be on the first two numbers, and the third sort on the remaining three or four numbers.

If there is a better way to sort the results I am all ears!
I am new to writing SQL statements, and I am open to all suggestions.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-17 : 16:39:55
Do you mean this?:

Select PartNum, Min, Max, Available, SalesSample, PendingSale, Notes, sort = dbo.GetTripForce(PartNum)
From dbo.DomeStock

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

extrapulp
Starting Member

9 Posts

Posted - 2010-06-21 : 11:12:20
tkizer,

yes that works great!

Thank you!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-21 : 12:24:17
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -