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)
 checking a value

Author  Topic 

etered
Starting Member

2 Posts

Posted - 2008-12-05 : 03:34:48
i need to check whether a value has a trailing \ at the end of a variable.

if @data_path does not have a trailing \ i need to add one? the code is below can someone look at this and let me know how i achieve this?

thanks in advance?

DECLARE @regkey NVARCHAR(260)
DECLARE @instance sysname
SELECT @instance = convert(sysname, SERVERPROPERTY('InstanceName'))
SELECT @regkey = 'SOFTWARE\Microsoft\'
if @instance is null
SELECT @regkey = @regkey + 'MSSQLServer\MSSQLServer'
else
SELECT @regkey = @regkey + 'Microsoft SQL Server\' + @instance + '\MSSQLServer'

EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
@regkey,
'DefaultData',
@param = @data_path OUTPUT

EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
@regkey,
'DefaultLog',
@param = @log_path OUTPUT

-- construct fully qualified data and log file names
declare @datasqlname sysname, @logsqlname sysname
declare @datafile sysname, @logfile sysname
SET @datasqlname = N'test'
SET @logsqlname = N'test_log'
will not have this present
SET @datafile = @data_path + @datasqlname + '.MDF'
SET @logfile = @log_path + @logsqlname + '.LDF'

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-12-05 : 05:12:42

--Check for trailing '\' and add if needed
If Right(@data_path,1)<>'\'
set @data_path=@data_path+ '\'
SET @datafile = @data_path + @datasqlname + '.MDF'
Go to Top of Page

etered
Starting Member

2 Posts

Posted - 2008-12-05 : 08:50:04
excellent that is the command i was looking for... will check out and let you know but a massive thanks..
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-12-05 : 09:17:36
welcome
Go to Top of Page
   

- Advertisement -