DECLARE @IP Varchar(20)
SET @IP='10.161.105.148'
SELECT SUBSTRING(@IP,1,LEN(@IP)-4)
-- This is get the Sub String of the IP
-- Result
--100.1601.105
-- Using Left in Sql Server
SELECT LEFT(@IP,LEN(@IP)-4)
SELECT RIGHT(@IP,LEN(@IP)-4)
Result
-----
10.161.105
61.105.148
DECLARE @MachineIP NVARCHAR(20)
SET @MachineIP='10.2.15.132'
-- Bellow Query is used to Reverse the given String
SELECT Reverse(@MachineIP)
-- This used to get First Three Part of the IP Address
SELECT SUBSTRING(@MachineIP ,1 ,Len(@MachineIP)-(CHARINDEX('.',Reverse(@MachineIP),-1)))
/*------ Result ------
231.51.2.01
10.2.15
---------------------- */
A Simple Example For Group By Having
Create table #temp(name varchar(20))
insert into #temp values('Siva')
insert into #temp values('Raghu')
SELECT Name +' - ' + Cast(count(Name)As varchar) FROM #temp Group by Name
--Having Name='siva'
drop table #temp
Result:
Babu - 2
Raghu - 1
Siva - 2



Read User's Comments