Retrieving a column value of a stored procedure using user defined function

I have stored procedure as below, I am trying to use a column value as function ie dbo.SfnParseJSON(@formData) and other column values as other column values. But for some reason, Store Procedure is taking too long to run. After getting these values I need to join to other tables that’s the next steps, could you please help is there any different alternates for this, any help would be very very helpful.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ALTER PROCEDURE [dbo].[SSRSAgreements]
@area varchar(50)
AS
BEGIN
declare @jsonName_EmergingBroker_DVBE NVARCHAR(500) = 'DVBE'
declare @jsonName_EmergingBroker_Minority NVARCHAR(500) = 'Minority'
declare @jsonName_EmergingBroker_Women NVARCHAR(500) = 'Women'
declare @jsonName_EmergingBroker_NotApplicable NVARCHAR(500) = 'NotApplicable'
declare @formDataTable table(
tempid int,
FormId uniqueidentifier not null,
CoreId uniqueidentifier,
FormData nvarchar(max)
)
insert into @formDataTable
select tempid=ROW_NUMBER() OVER(ORDER BY(SELECT NULL)),
FormId=FormId, CoreId=CoreId, FormData=FormData from tbForm
DECLARE @tempHierarhy TABLE(
Element_ID INT NOT NULL, /* internal surrogate primary key gives the order of parsing and the list order */
SequenceNo [int] NULL, /* the place in the sequence for the element */
Parent_ID INT,/* if the element has a parent then it is in this column. The document is the ultimate parent, so you can get the structure from recursing from the document */
[Object_ID] INT,/* each list or object has an object id. This ties all elements to a parent. Lists are treated as objects here */
[Name] NVARCHAR(2000),/* the name of the object, null if it hasn't got one */
StringValue NVARCHAR(MAX) NOT NULL,/*the string representation of the value of the element. */
ValueType VARCHAR(10) NOT null /* the declared type of the value represented as a string in StringValue*/,
FormId uniqueidentifier not null,
CoreId uniqueidentifier,
PRIMARY KEY (Element_ID)
)
DECLARE @MaxTempId int;
DECLARE @CurrentTempId int;
SELECT @MaxTempId = MAX(TempId) from @formDataTable
SELECT @CurrentTempId = MIN(TempId) from @formDataTable
while @CurrentTempId <= @MaxTempId
begin
declare @FormId uniqueidentifier=null
declare @CoreId uniqueidentifier=null
declare @formData nvarchar(max)=null
select @FormId=FormId, @CoreId=CoreId, @formData=formData from @formDataTable where tempid=@CurrentTempId
INSERT INTO @tempHierarhy
Select *, @FormId, @CoreId from dbo.SfnParseJSON(@formData)
-- Increment list of forms identifier
set @CurrentTempId = @CurrentTempId + 1
end
select * from @tempHierarhy
end
</code>
<code>ALTER PROCEDURE [dbo].[SSRSAgreements] @area varchar(50) AS BEGIN declare @jsonName_EmergingBroker_DVBE NVARCHAR(500) = 'DVBE' declare @jsonName_EmergingBroker_Minority NVARCHAR(500) = 'Minority' declare @jsonName_EmergingBroker_Women NVARCHAR(500) = 'Women' declare @jsonName_EmergingBroker_NotApplicable NVARCHAR(500) = 'NotApplicable' declare @formDataTable table( tempid int, FormId uniqueidentifier not null, CoreId uniqueidentifier, FormData nvarchar(max) ) insert into @formDataTable select tempid=ROW_NUMBER() OVER(ORDER BY(SELECT NULL)), FormId=FormId, CoreId=CoreId, FormData=FormData from tbForm DECLARE @tempHierarhy TABLE( Element_ID INT NOT NULL, /* internal surrogate primary key gives the order of parsing and the list order */ SequenceNo [int] NULL, /* the place in the sequence for the element */ Parent_ID INT,/* if the element has a parent then it is in this column. The document is the ultimate parent, so you can get the structure from recursing from the document */ [Object_ID] INT,/* each list or object has an object id. This ties all elements to a parent. Lists are treated as objects here */ [Name] NVARCHAR(2000),/* the name of the object, null if it hasn't got one */ StringValue NVARCHAR(MAX) NOT NULL,/*the string representation of the value of the element. */ ValueType VARCHAR(10) NOT null /* the declared type of the value represented as a string in StringValue*/, FormId uniqueidentifier not null, CoreId uniqueidentifier, PRIMARY KEY (Element_ID) ) DECLARE @MaxTempId int; DECLARE @CurrentTempId int; SELECT @MaxTempId = MAX(TempId) from @formDataTable SELECT @CurrentTempId = MIN(TempId) from @formDataTable while @CurrentTempId <= @MaxTempId begin declare @FormId uniqueidentifier=null declare @CoreId uniqueidentifier=null declare @formData nvarchar(max)=null select @FormId=FormId, @CoreId=CoreId, @formData=formData from @formDataTable where tempid=@CurrentTempId INSERT INTO @tempHierarhy Select *, @FormId, @CoreId from dbo.SfnParseJSON(@formData) -- Increment list of forms identifier set @CurrentTempId = @CurrentTempId + 1 end select * from @tempHierarhy end </code>
ALTER PROCEDURE [dbo].[SSRSAgreements]
    @area varchar(50)
AS
BEGIN

declare @jsonName_EmergingBroker_DVBE NVARCHAR(500) = 'DVBE'
declare @jsonName_EmergingBroker_Minority NVARCHAR(500) = 'Minority'
declare @jsonName_EmergingBroker_Women NVARCHAR(500) = 'Women'
declare @jsonName_EmergingBroker_NotApplicable NVARCHAR(500) = 'NotApplicable'


declare @formDataTable table(
    tempid int,
    FormId uniqueidentifier not null,
    CoreId uniqueidentifier,
    FormData nvarchar(max)
)

insert into @formDataTable
select tempid=ROW_NUMBER() OVER(ORDER BY(SELECT NULL)),
        FormId=FormId, CoreId=CoreId, FormData=FormData from tbForm




DECLARE @tempHierarhy TABLE(
    Element_ID INT NOT NULL, /* internal surrogate primary key gives the order of parsing and the list order */
    SequenceNo [int] NULL, /* the place in the sequence for the element */
    Parent_ID INT,/* if the element has a parent then it is in this column. The document is the ultimate parent, so you can get the structure from recursing from the document */
    [Object_ID] INT,/* each list or object has an object id. This ties all elements to a parent. Lists are treated as objects here */
    [Name] NVARCHAR(2000),/* the name of the object, null if it hasn't got one */
    StringValue NVARCHAR(MAX) NOT NULL,/*the string representation of the value of the element. */
    ValueType VARCHAR(10) NOT null /* the declared type of the value represented as a string in StringValue*/,
    FormId uniqueidentifier not null,
    CoreId uniqueidentifier,

    PRIMARY KEY (Element_ID)
)

DECLARE @MaxTempId int;
DECLARE @CurrentTempId int;
SELECT @MaxTempId = MAX(TempId) from @formDataTable
SELECT @CurrentTempId = MIN(TempId) from @formDataTable
while @CurrentTempId <= @MaxTempId
begin
        declare @FormId uniqueidentifier=null
        declare @CoreId uniqueidentifier=null
        declare @formData nvarchar(max)=null

        select @FormId=FormId, @CoreId=CoreId, @formData=formData from @formDataTable where tempid=@CurrentTempId
        
        INSERT INTO @tempHierarhy
        Select *, @FormId, @CoreId from dbo.SfnParseJSON(@formData)
    -- Increment list of forms identifier
        set @CurrentTempId = @CurrentTempId + 1
end

select * from @tempHierarhy
end

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật