/****** Object:  StoredProcedure [dbo].[Proc_TA_SelectedTerminal]    Script Date: 28-09-2022 09:25:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


-- Proc_TA_SelectedTerminal @TerminalID='1,2,3,4'

Create Proc [dbo].[Proc_TA_SelectedTerminal]
(
	@TerminalID nvarchar(Max)
)
As
Begin
	Declare @RowCountTerminalID int
	create table #Temp_TerminalID(TerminalID varchar(25))
	if(@TerminalID is not null and @TerminalID <> '')
		begin
			if(SUBSTRING(@TerminalID,LEN(@TerminalID),len(@TerminalID)) = ',')
			begin
				set @TerminalID=SUBSTRING(@TerminalID,0,len(@TerminalID))
			end
				insert into #Temp_TerminalID
				select value from dbo.split(@TerminalID,',')
				select @RowCountTerminalID=COUNT(TerminalID) from #Temp_TerminalID
	    end
		
		Select Terminal_ReaderID,Terminal_Name,Terminal_Description,td.Raw_Data_Format from TA_Tbl_Terminal t1 inner join #Temp_TerminalID t2 on t2.TerminalID=t1.Terminal_ReaderID 
		inner join TA_tbl_TerminalDatatype td on t1.TerminalDatatype_ID =td.TerminalDatatype_ID
End
