Convert CSV Values to INT

The given function converts the comma seperated values (CSV) to integer.


CREATE function [dbo].[CsvToInt] (@id varchar(5000))
returns @table table (wd_code int identity(1,1), [id] int)
as
begin
declare @separator char(1)
set @separator = ','
declare @separator_position int
declare @array_value varchar(5000)
set @id = @id + ','
while patindex('%,%' , @id) <> 0
begin
select @separator_position = patindex('%,%' , @id)
select @array_value = left(@id, @separator_position - 1)
if(@array_value = 'null')
insert @table ([id])
values (null)
else
insert @table ([id])
values (cast(@array_value as int))
select @id = stuff(@id, 1, @separator_position, '')
end
return
end

Check Locked Tables


Below is the query by which you can check if the table is locked or not


select distinct object_name(a.rsc_objid), a.req_spid, b.loginame
from master.dbo.syslockinfo a (nolock) join
master.dbo.sysprocesses b (nolock) on a.req_spid=b.spid
where object_name(a.rsc_objid) is not null
and a.rsc_objid = OBJECT_ID('TableName')