Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concatenate xp_getnetname function with string

Author  Topic 

fafastrungen
Starting Member

5 Posts

Posted - 2007-07-26 : 03:11:13
Hi, I need to concatenate the xp_getnetname function with a string. When I execute xp_getnetname I get:

"ITANIUM01"

and I need to concatenate it with the next string:

"\\10.50.100.1\BACKUPS\"

to get something like this:

"\\10.50.100.1\BACKUPS\ITANIUM01"

so, how can I accomplish this ?



Thanks in advance.

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-07-26 : 04:41:58
you cannot get the output of a procedure concatenated with a string. However, you can use an alternative by getting the output in a table type variable and concatenate it with string value.
Go to Top of Page

fafastrungen
Starting Member

5 Posts

Posted - 2007-07-26 : 06:34:41
quote:
Originally posted by shallu1_gupta

you cannot get the output of a procedure concatenated with a string. However, you can use an alternative by getting the output in a table type variable and concatenate it with string value.



I knew that I can insert the result of the function into a table declared as variable, but what I was trying to do is get everything in one line, something like this:

Select "\\10.50.100.1\BACKUPS\" + xp_getnetname

Thanks for your answer, I know now that I must find another way.
Go to Top of Page

yoshidamiki
Starting Member

1 Post

Posted - 2007-08-30 : 03:07:50
drop table #tmp
create table #tmp([Server Net Name] varchar(64))
insert into #tmp exec xp_getnetname
--select * from #tmp

declare @t as nvarchar(64)
set @t=(select [Server Net Name] from #tmp)

print '\\10.50.100.1\BACKUPS\' + @t
Select '\\10.50.100.1\BACKUPS\' + @t
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-30 : 03:55:14
xp_getnetname is undocumented.

I think you should go for the registry read method, since now and then some undocumented methods are removed.


DECLARE @test varchar(20)
EXEC master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Test', 'TestValue', @test OUTPUT

SELECT @test



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-04 : 09:17:24
[code]CREATE VIEW dbo.vwDatabaseInformation
AS

SELECT 'MachineName' AS PropertyName, SERVERPROPERTY('MachineName') AS PropertyValue UNION ALL
SELECT 'ServerName', SERVERPROPERTY('ServerName') UNION ALL
SELECT 'InstanceName', SERVERPROPERTY('InstanceName') UNION ALL
SELECT 'Edition', SERVERPROPERTY('Edition') UNION ALL
SELECT 'ProductVersion', SERVERPROPERTY('ProductVersion') UNION ALL
SELECT 'ProductLevel', SERVERPROPERTY('ProductLevel') UNION ALL
SELECT 'EngineEdition', SERVERPROPERTY('EngineEdition') UNION ALL
SELECT 'ComputerNamePhysicalNetBIOS', SERVERPROPERTY('ComputerNamePhysicalNetBIOS')[/code]
SELECT PropertyValue FROM dbo.vwDatabaseInformation WHERE PropertyName = 'MachineName'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-04 : 09:18:51
And in your case

SELECT '\\10.50.100.1\BACKUPS\' + SERVERPROPERTY('MachineName')

or

SELECT '\\10.50.100.1\BACKUPS\' + PropertyValue
FROM dbo.vwDatabaseInformation
WHERE PropertyName = 'MachineName'




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -