Use proc to obtain the IP address

Source: Internet
Author: User
Tags rtrim

-- ===================================================== ======
-- Create procedure basic template
-- ===================================================== ======
-- Creating the store procedure
If exists (Select name
From sysobjects
Where name = n' ccyt _ getip'
And type = 'P ')
Drop procedure ccyt_getip
Go

Create procedure ccyt_getip
@ Sname varchar (50)

As

If @ sname = '.'
Begin
Set @ sname =servername
End
If @ sname = 'local'
Begin
Set @ sname =servername
End

If @ sname like '%. %'
Begin
Select servername = @ sname, serverip = @ sname
End
Else

Begin

Create Table # IP (ID int identity (1, 1), Re varchar (200 ))

Declare @ s varchar (1000)
Set @ s = 'ping' + ltrim (rtrim (@ sname) + '-a-n 1-l 1'
Insert # IP (re) exec master .. xp_mongoshell @ s

Select servername = ltrim (rtrim (@ sname), serverip = stuff (left (Re, charindex (']', RE)-1), 1, charindex ('[', re ),'')
From # IP
Where id = 2

Drop table # IP
End

Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.