Thursday, June 5, 2014

To Check whether Given IP Address is 'Pinging'

-- To Check To Check whether Given IP Address is 'Pinging'


drop table #TempTable
declare @IP as varchar(15)
declare @cmd as varchar(300)
set @IP = '192.168.50.200'  -- fill the ip address here
set @cmd = 'ping ' + @IP
--Create table
create table #TempTable (output varchar(150) default(''))
insert into #TempTable
exec xp_cmdshell @cmd

select * from #TempTable where output is not null


Use of function 'LEFT' in SQL 2008 R2

-- Use of LEFT function

select LEFT('WindowXP',1as LEFTOUT

-- In above function LEFT which removes the characters in a string variable from the starting point mentioned next to the string variable such as 1

Results is


How to find the IP Address of the client Machine in SQL Server 2008 R2


-- Check whether particular table exists in the database
if exists (select * from sys.objects where object_id = object_id(N'[#table]'))
begin
drop table #table
end
use tempdb
go
--Create the temp table #table
create table #table (IPValues varchar(200))
insert into #table exec master..xp_cmdshell 'ipconfig'
-- select the data from the table #table
select * from #table where IPValues is not null
-- You will get results like this