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.
| 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 sysnameSELECT @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 OUTPUTEXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @regkey, 'DefaultLog', @param = @log_path OUTPUT-- construct fully qualified data and log file namesdeclare @datasqlname sysname, @logsqlname sysnamedeclare @datafile sysname, @logfile sysnameSET @datasqlname = N'test'SET @logsqlname = N'test_log'will not have this presentSET @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 neededIf Right(@data_path,1)<>'\'set @data_path=@data_path+ '\'SET @datafile = @data_path + @datasqlname + '.MDF' |
 |
|
|
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.. |
 |
|
|
darkdusky
Aged Yak Warrior
591 Posts |
Posted - 2008-12-05 : 09:17:36
|
| welcome |
 |
|
|
|
|
|