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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Text file into Stored Procedures

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2010-12-21 : 02:41:12
Dear all,

test.txt
--------
<tbpartner>
<HROW

code="MY000002"

description="Giant LTD."

nric="3232323"

bankaccname="Joel"

/></tbpartner>



Stored Procedures:-
-------------------
CREATE proc spSave(
@xml XML
)
as

declare @RecId int
BEGIN
INSERT INTO [tbpartner]
([code]
,[description]
,[nric]
,[bankaccname])
SELECT T.Item.value('@code', 'NVARCHAR(30)') [code],
T.Item.value('@description', 'NVARCHAR(100)') [description],
T.Item.value('@nric, 'INT') [nric],
T.Item.value('@bankaccname', 'INT') [bankaccname]
FROM @xml.nodes('/tbpartner/HROW') AS T(Item)
set @RecId = SCOPE_IDENTITY()

RETURN 0
END


How can i pass the text file info into stored procedures?
Please advise.

Thank you.

Regards,
Micheale

Sachin.Nand

2937 Posts

Posted - 2010-12-21 : 07:21:35
You cannot.

You will have to pass the contents of the text file as a parameter for the SP.

PBUH

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2010-12-21 : 08:24:11
An alternative might be to use bulk insert (or bcp or SSIS) to import the data in the text file to a staging table in your database and then have the stored procedure read the data from that staging table.

http://msdn.microsoft.com/en-us/library/ms188365.aspx has examples that show how to use bulk insert to get data from a file into a database table.
Go to Top of Page
   

- Advertisement -