dbTalk Databases Forums  

sp_executeSQL Database Files.

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss sp_executeSQL Database Files. in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Roger
 
Posts: n/a

Default sp_executeSQL Database Files. - 04-28-2007 , 10:41 AM






I would really appreciate if anybody can correct me in the following query.

In the following query, I am passing the database name and getting
DataFileName in to the output variable, I would appreciate if any body can
look into that and solve this problem.


declare @dbFile varchar(100),
@dbName varchar(100)
set @dbName = 'myDb'
execute
sp_executesql
N'select @dbFileName =
SUBSTRING(FileName,1,len(FileName)) from '+@dbName+'.dbo.sysfiles where
fileId = 1',
N'@dbFileName varchar(100) output',
@dbFile

Thanks in advance.



Reply With Quote
  #2  
Old   
Ayad Shammout
 
Posts: n/a

Default Re: sp_executeSQL Database Files. - 07-26-2007 , 03:32 PM






Try this:

declare @dbFile varchar(100),

@dbName varchar(100),

@string nvarchar(4000)

set @dbName = 'myDB'

Set @string = N'select SUBSTRING(FileName,1,len(FileName)) from
'+@dbName+'.dbo.sysfiles where

fileId = 1'

execute sp_executesql @String, N'@dbFileName varchar(100) output', @dbFile



Ayad Shammout



"Roger" <naissani (AT) hotmail (DOT) com> wrote

Quote:
I would really appreciate if anybody can correct me in the following query.

In the following query, I am passing the database name and getting
DataFileName in to the output variable, I would appreciate if any body can
look into that and solve this problem.


declare @dbFile varchar(100),
@dbName varchar(100)
set @dbName = 'myDb'
execute
sp_executesql
N'select @dbFileName =
SUBSTRING(FileName,1,len(FileName)) from '+@dbName+'.dbo.sysfiles where
fileId = 1',
N'@dbFileName varchar(100) output',
@dbFile

Thanks in advance.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.