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
 General SQL Server Forums
 New to SQL Server Programming
 stor procedure

Author  Topic 

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-06-06 : 08:33:47
how to I create stored procedure for bulk insert


bulk insert mytable
from '@ggg'
with
(formatfile='c:\temp\lll.txt')

kmkmmm

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-06 : 10:40:46
you need dynamic sql for that

CREATE PROC BulkInsertData
@ggg varchar(1000)
AS
DECLARE @SQL varchar(3000)
SET @SQL = 'bulk insert mytable
from ''' + @ggg + '''
with
(formatfile=''c:\temp\lll.txt'')'
EXEC(@SQL)
GO



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-06-06 : 10:54:52
thank you
but

EXECUTE BulkInsertData('C:\temp\abseron060400.txt')

-----------
error
Line 1: Incorrect syntax near 'C:\temp\abseron060400.txt'.


kmkmmm
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-06-06 : 21:44:24
quote:
Originally posted by pascal_jimi

thank you
but

EXECUTE BulkInsertData('C:\temp\abseron060400.txt')

-----------
error
Line 1: Incorrect syntax near 'C:\temp\abseron060400.txt'.


kmkmmm



EXECUTE BulkInsertData 'C:\temp\abseron060400.txt'

OR

EXECUTE BulkInsertData @ggg = 'C:\temp\abseron060400.txt'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -