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.
Author |
Topic |
nitinsomal
Starting Member
4 Posts |
Posted - 2013-12-26 : 07:58:18
|
update #T_EquipmentSchedule set OffTimeCodes = dbo.fn_GetResourceActivityCodes(@scenarioID, @scheduleTypeID, #T_EquipmentSchedule.EquipmentID, #T_EquipmentSchedule.ScheduleDate)When i try to update #T_EquipmentSchedule temporary table it is taking too much time, how i can improve the performance of queryNote:dbo.fn_GetResourceActivityCodes(@scenarioID, @scheduleTypeID, #T_EquipmentSchedule.EquipmentID, #T_EquipmentSchedule.ScheduleDate)is working fine |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2013-12-26 : 12:40:22
|
You'll need to post the code of the function for us to help.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
nitinsomal
Starting Member
4 Posts |
Posted - 2013-12-27 : 08:22:44
|
quote: Originally posted by tkizer You'll need to post the code of the function for us to help.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/
ALTER FUNCTION [dbo].[fn_GetResourceActivityCodes]( @scenarioID numeric(18,0), @equipmentScheduleTypeID int, @equipmentID numeric(18,0), @scheduleDate date)RETURNS nvarchar(max)ASBEGIN -- declare @activityCodes nvarchar(max) declare @materialCode_Lunch nvarchar(50) = '80' declare @materialID_Lunch numeric(18,0) -- -- get the lunch material ID select @materialID_Lunch = M.MaterialID from dbo.Material (nolock) M where M.ScenarioID = @scenarioID and M.MaterialCode = @materialCode_Lunch -- -- select @activityCodes = substring ( (select distinct ',' + dbo.fn_GetCSAActivityCode(@scenarioID, ES.MaterialID) as [text()] from EquipmentSchedule (nolock) ES where ES.ScenarioID = @scenarioID and EquipmentScheduleTypeID = @equipmentScheduleTypeID and MaterialID not in (@materialID_Lunch) and cast(StartDateTime as date) = @scheduleDate and equipmentid = @equipmentID order by 1 desc for xml path('')), 2, 8000) -- return @activityCodesENDNote: It is workin fine |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-28 : 01:42:01
|
why do you need nested UDFs here? whats fn_GetCSAActivityCode doing?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
nitinsomal
Starting Member
4 Posts |
Posted - 2013-12-28 : 05:37:11
|
to retrive the ActivityCodes |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-28 : 09:48:27
|
quote: Originally posted by nitinsomal to retrive the ActivityCodes
Why cant that be done inline by means of correlated query?using nested UDFs will have an impact on performance especially for large datasets------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Kristen
Test
22859 Posts |
Posted - 2014-01-02 : 07:30:27
|
I don't know if it is the issue you are facing - i.e. whether just calling the Function ONCE is slow?We have a function that was called very VERY often in our code. It did a relatively simple query, but the query was such that it was recompiled often / every time the function was called. The recompile caused the function to BLOCK, and that caused other function calls to be queued, and that killed performance in our APP.I went off using Function to "wrap" simple queries after that! |
|
|
|
|
|
|
|