SQL: Create File/Filegroup

Hi all! Well, actually this is a SQL problem, but as it is directly related to a NAVISION system I like to post it here … I have this TransactSQL script: alter database MyDatabase add filegroup Test; declare @newname varchar (50), @newfile varchar (250); select @newname = name from MyDatabase.dbo.sysfiles where groupid = 1; set @newname = rtrim(@newname) + ‘_Index’; select @newfile = filename from MyDatabase.dbo.sysfiles where groupid = 1; set @newfile = left(rtrim(@newfile), len(rtrim(@newfile)) - 4) + ‘_Index.ndf’; print @newname; print @newfile; alter database MyDatabase add file (name = @newname, filename = @newfile) to filegroup Test; The idea is, to create the FileGroup “Test”. Then add a new db file where the name and filename are modifications of an exisiting file. Finally, the variables @newname and @newfile contain the required strings. The problem is the last alter database statement: Within the add file part, the variables @… are not recognized/valid. Why? And what do I have to change to get it running? Can you find the error? Thanks in advance! Regards,

alter database MyDatabase add file (name = @newname, filename = @newfile) to filegroup Test; change to: EXEC (‘alter database pubs add file (NAME = ‘+@newname+’, filename = ‘’’+@newfile+’’’) to filegroup Test;’)

Works perfectly! [:D] Thank you very much!