forked from klebermoura/mssql_array
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsp_set_array.sql
More file actions
26 lines (18 loc) · 988 Bytes
/
sp_set_array.sql
File metadata and controls
26 lines (18 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
create or alter procedure dbo.sp_set_array
@nmArray varchar(200),
@indice int,
@valor varchar(8000)
with encryption
as
begin
-- exemplo: exec dbo.sp_set_array 'teste', 1, '300'
declare @nmAux varchar(100)
declare @sql varchar(2000)
if (@nmArray is null or @nmArray = '') or (@indice is null)
raiserror('parametros não informados.',16,1)
set @nmAux = convert(varchar,@@SPID)
set @nmArray = @nmArray +'_'+@nmAux
set @sql = 'if exists (select * from tempdb.sys.objects where type = ''U'' and name = ''' + '##'+@nmArray + ''') begin if exists (select ''x'' from ##' + @nmArray + ' where indice = ' + convert(varchar,@indice)+') update ##'+@nmArray + ' set valor = ''' + isnull(@valor,'') + ''' where indice = ' + convert(varchar, @indice) + ' else insert into ##'+@nmArray + ' (indice, valor) values (' + convert(varchar,@indice) + ', ''' +isnull(@valor,'') + ''') end else raiserror(''Array não existe'',16,1) '
exec (@sql)
end
go