How to Construct a URL for Webservices using variable parameters
I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.
My application will pass 2 parameters to the URL, namely date, and Staff.ID
. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.
Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID
. I have tried constructing the URL by using declare statements and the parameters but did not work.
The script:
DECLARE @response NVARCHAR(max);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
@response OUTPUT;
BEGIN
--Insert into Schedules
--(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response) ;
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY
OpenJson(Blocks)
WITH
(StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END;
go
sql sql-server tsql
add a comment |
I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.
My application will pass 2 parameters to the URL, namely date, and Staff.ID
. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.
Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID
. I have tried constructing the URL by using declare statements and the parameters but did not work.
The script:
DECLARE @response NVARCHAR(max);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
@response OUTPUT;
BEGIN
--Insert into Schedules
--(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response) ;
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY
OpenJson(Blocks)
WITH
(StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END;
go
sql sql-server tsql
add a comment |
I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.
My application will pass 2 parameters to the URL, namely date, and Staff.ID
. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.
Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID
. I have tried constructing the URL by using declare statements and the parameters but did not work.
The script:
DECLARE @response NVARCHAR(max);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
@response OUTPUT;
BEGIN
--Insert into Schedules
--(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response) ;
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY
OpenJson(Blocks)
WITH
(StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END;
go
sql sql-server tsql
I have a script which works. I want to turn this into a procedure, so I can call the procedure from an application. However, I have 2 parameters within the script that form part of the URL that is used to call webservices. The said script is below.
My application will pass 2 parameters to the URL, namely date, and Staff.ID
. Both are highlighted in bold Italics in the script. Yes, the script will return the correct values from the JSON output from the application concerned. So, it all works as it stands.
Now, I want to create this as a procedure to call from my application (a PowerApps application) but pass to the procedure both the date and Staff.ID
. I have tried constructing the URL by using declare statements and the parameters but did not work.
The script:
DECLARE @response NVARCHAR(max);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=***2018-11-21***&Staff.ID=***249***',
@response OUTPUT;
BEGIN
--Insert into Schedules
--(SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
Select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response) ;
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY
OpenJson(Blocks)
WITH
(StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END;
go
sql sql-server tsql
sql sql-server tsql
edited Nov 22 '18 at 23:25
Makyen
20.5k83971
20.5k83971
asked Nov 22 '18 at 22:10
PaulBPaulB
61
61
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I've assumed your query all works, and I've just encapsulated it within a SP:
create procedure dbo.MyProcedureName
(
@Date date
, @StaffId int
)
as
begin
DECLARE @response NVARCHAR(max), @Url varchar(max);
set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService @Url, @response OUTPUT;
--insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response);
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY OpenJson(Blocks)
WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END
go
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438511%2fhow-to-construct-a-url-for-webservices-using-variable-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've assumed your query all works, and I've just encapsulated it within a SP:
create procedure dbo.MyProcedureName
(
@Date date
, @StaffId int
)
as
begin
DECLARE @response NVARCHAR(max), @Url varchar(max);
set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService @Url, @response OUTPUT;
--insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response);
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY OpenJson(Blocks)
WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END
go
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
add a comment |
I've assumed your query all works, and I've just encapsulated it within a SP:
create procedure dbo.MyProcedureName
(
@Date date
, @StaffId int
)
as
begin
DECLARE @response NVARCHAR(max), @Url varchar(max);
set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService @Url, @response OUTPUT;
--insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response);
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY OpenJson(Blocks)
WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END
go
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
add a comment |
I've assumed your query all works, and I've just encapsulated it within a SP:
create procedure dbo.MyProcedureName
(
@Date date
, @StaffId int
)
as
begin
DECLARE @response NVARCHAR(max), @Url varchar(max);
set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService @Url, @response OUTPUT;
--insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response);
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY OpenJson(Blocks)
WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END
go
I've assumed your query all works, and I've just encapsulated it within a SP:
create procedure dbo.MyProcedureName
(
@Date date
, @StaffId int
)
as
begin
DECLARE @response NVARCHAR(max), @Url varchar(max);
set @Url = 'https://powercomm.simprosuite.com/api/v1.0/companies/1/schedules/?access.token=383abc4084a2b8dcbf508252e4a0313762fd623b&Date=' + convert(varchar(10), @Date, 23) + '&Staff.ID=' + convert(varchar(38),@StaffId);
--get the data from the provider as JSON
EXECUTE dbo.GetWebService @Url, @response OUTPUT;
--insert into Schedules (SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime)
select SchedID, Type, JobNo, TotalHrs, EmployeeID, SchedDate, StartTime, FinishTime
FROM OpenJson(@response);
with (SchedID numeric N'$.ID', Type CHAR(15) N'$.Type', JobNo nvarchar(5) N'$.Reference', TotalHrs Dec(4,2) N'$.TotalHours', SchedDate Date N'$.Date', EmployeeID numeric(6) N'$.Staff.ID', Blocks nvarchar(max) N'$.Blocks' as JSON)
OUTER APPLY OpenJson(Blocks)
WITH (StartTime datetimeoffset N'$.ISO8601StartTime', FinishTime datetimeoffset N'$.ISO8601EndTime' );
END
go
answered Nov 22 '18 at 22:19
Dale BurrellDale Burrell
3,10032351
3,10032351
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
add a comment |
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
Dale,Works perfectly thank you.Paul
– PaulB
Nov 22 '18 at 23:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438511%2fhow-to-construct-a-url-for-webservices-using-variable-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown