February 29, 2016 at 1:00 am
..
February 29, 2016 at 1:20 am
)
February 29, 2016 at 4:44 am
THANKS
Is it possible in order to run the function to use
SELECT * FROM dbo.DIS ('12', '33')
February 29, 2016 at 5:15 am
Nope
-- Gianluca Sartori
February 29, 2016 at 5:59 am
The reason you can't pass individual parameter values is that the function is accepting a table, not individual values.
February 29, 2016 at 8:53 am
This is a multi-statement TVP. Those should be avoided at all costs. DEVASTATINGLY BAD stuff happens! Also, this one is completely ridiculous. Simply calculate the sum yourself on your on object in your own code.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
February 29, 2016 at 9:38 am
I agree 100% with Kevin that this function is ridiculous. As he said this a horrible way to build a table valued function from a performance standpoint. After your insert into the return you declare a new variable and then set it to the sum of weight. What is the point of that?
Do you realize that when you pass in a table valued parameter it behaves exactly like a table. You have a number of unnecessary steps in here. I don't get the point of the cte at all. It is nothing but a select *. And you really don't even need to bother with the local table variable anyway. All you are doing there is creating another copy of the inbound data. If you want greatly streamline the function you posted you could shorten it to this.
CREATE FUNCTION dbo.DIS
(
@myTVP Code_List READONLY
)
RETURNS TABLE AS RETURN
select sum(weight) as dis_code
from @myTVP
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply