SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE  procedure [dbo].[p_sequences_create_counters]
	@sequence_code ais_code_short = '%'
as
	
	if @sequence_code = '%'
	begin
		insert into sq_sequences_counters(	seqc_sequence_code, seqc_prefix, seqc_counter_value )
		select								seq_sequence_code,	s.seq_prefix, 0
		from sq_sequences s
		where not exists( select 1 from sq_sequences_counters where seqc_sequence_code = seq_sequence_code)
	end
	else
	begin
		insert into sq_sequences_counters(	seqc_sequence_code, seqc_prefix, seqc_counter_value )
		select								seq_sequence_code,	s.seq_prefix,  0
		from	sq_sequences s
		where	s.seq_sequence_code = @sequence_code
		AND		not exists( select 1 from sq_sequences_counters where seqc_sequence_code = @sequence_code)
	end
GO
