Skip to content

Commit 729e52f

Browse files
committed
added get_sample procedure
1 parent c48aada commit 729e52f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

db/sql/07-get_sample.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
create or alter procedure dbo.get_sample
2+
@id int = null,
3+
@url nvarchar(1000) = null
4+
as
5+
set nocount on;
6+
set xact_abort on
7+
8+
if (@id is not null and @url is not null)
9+
begin
10+
raiserror('Cannot specify both id and url', 16, 1)
11+
return
12+
end
13+
14+
declare @sid int
15+
16+
if (@url is not null)
17+
begin
18+
select @sid = id from dbo.samples where url = @url
19+
end else begin
20+
set @sid = @id
21+
end
22+
23+
if (@sid is null)
24+
begin
25+
raiserror('Sample not found', 16, 1)
26+
return
27+
end
28+
29+
select
30+
json_object(
31+
'name':[name],
32+
'description':[description],
33+
'notes':[notes],
34+
'details': cast([details] as json),
35+
'url': [url]
36+
) as sample_json
37+
from
38+
dbo.samples
39+
where
40+
id = @sid
File renamed without changes.

0 commit comments

Comments
 (0)