February 24, 2015 at 10:15 am
declare @filename varchar(255),
@path varchar(255),
@sql varchar(8000),
@sql3 varchar(8000),
@cmd1 varchar(1000),
@cmd2 varchar(1000),
@cmd3 varchar(1000),
@cmd4 varchar(1000)
SET @path = '\\fileserver1\Repository\Cost Reports\Latest Cost Reports\'+ @year +'\Hospital\HOSPFY' +@year
SET @cmd1 = 'dir'+' "'+'\\fileserver1\Repository\Cost Reports\Latest Cost Reports\'+ @year +'\Hospital\HOSPFY' +@year +'"' +'\*ALPHA.CSV /b/s'
SET @SQL3 = 'INSERT INTO ' + @bd_name + '.dbo'+'.ALLFILENAMES(WHICHFILE)' + 'EXEC Master..xp_cmdShell ' + @cmd1
But i am getting the value as
INSERT INTO Cost_reports.dbo.ALLFILENAMES(WHICHFILE)EXEC Master..xp_cmdShell dir "\\fileserver1\Repository\Cost Reports\Latest Cost Reports\2009\Hospital\HOSPFY2009"\*ALPHA.CSV /b/s
But it has to be this -
EXEC Master..xp_cmdShell ' dir "\\fileserver1\Repository\Cost Reports\Latest Cost Reports\2009\Hospital\HOSPFY2009"\*ALPHA.CSV /b/s'
i need to set a Apostrophe in front of dir and at the end
Please let me know how do i add it
February 24, 2015 at 10:26 am
Double up on the quotes.
declare @sql varchar(1000)
select @sql = 'INSERT dbo.mytest SELECT 'insert sales select ''test'' '
Also, watch your spaces. You are missing a few.
February 24, 2015 at 10:28 am
What Steve said (I just saw his response as I was about to reply)...
This is a good article SSC on the apostrophe topic... http://www.sqlservercentral.com/articles/T-SQL/95670/
-- Itzik Ben-Gan 2001
February 24, 2015 at 10:45 am
Used this SET @SQL3 = 'INSERT INTO ' + '2009' + '.dbo.ALLFILENAMES(WHICHFILE) EXEC Master..xp_cmdShell ''' + @cmd1 + ''''
Its working now thank you
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy