Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Use Select Query Result as a Function Argument

$
0
0

I have a larger query that consists of a lot of parenthetical SELECT statements. Some of these parenthetical SELECT statements are results of table-based function results. To make things briefer, here is a snippet that doesn't return anything for the function result. I need to feed the Supplier Code into the function for each row of the result. Since this is a table-based function, I purposely am pulling just the top row of its result.

Any suggestions on how I can handle this? I cannot directly to refer to the Su.Code value as the function argument, so I tried using local variables. Still I wind up with NULL as the result.

declare @Supplier varchar(255)
declare @OwnedCost money
select top 10 @Supplier = Su.Code,
@OwnedCost = (select TOP 1 OwnedCost from dbo.fncVendorHistorical(@Supplier, '6/1/2013', '6/1/2013'))
 from tbl330_Suppliers Su order by Su.Code 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>