Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


INSERTION


INSERTION

Author
Message
kapil_kk
kapil_kk
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2417 Visits: 2763
HI all,

I have a table TableA with structure:
CREATE TABle tABLEA
(
ID INT,
SourceData nvarchar(MAX)
)

Column source data contains INSERT query.
I have 2 lakhs records in the table and I want to execute all INSERT statment of column SourceData at once..
How can I achieve this?

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
John Mitchell-245523
John Mitchell-245523
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7414 Visits: 15114
Loop through the table and execute the statements one by one. Either that or write a query to build one set of INSERT statements and execute that in one go. The effect is about the same - either way, you can't run all the INSERTs at once.

John
David Burrows
David Burrows
SSCertifiable
SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)

Group: General Forum Members
Points: 7963 Visits: 9411
Depending on the data and insert statements you could parse the insert statements into another table and then insert from there


Far away is close at hand in the images of elsewhere.

Anon.


Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8506 Visits: 18113
To build one set as John said:

DROP TABLE #TableA
CREATE TABlE #TableA
(
ID INT,
SourceData nvarchar(MAX)
)

INSERT INTO #TableA
VALUES(1, 'INSERT TableX VALUES( 1''Something'')'),
(2, 'INSERT TableY VALUES( ''Something Else'', 1)'),
(3, 'INSERT TableX VALUES( ''Something More'', GETDATE())')

DECLARE @SQL nvarchar(MAX)
SELECT @SQL = (SELECT 'EXEC( ''' + REPLACE( SourceData, '''', '''''') + ''')' + CHAR(10)
FROM #TableA
FOR XML PATH(''))

PRINT @SQL


Reference: http://www.sqlservercentral.com/articles/comma+separated+list/71700/

I suppose that you will have everything double checked before doing this process as some mistake might give you trouble and make the query fail. You should try to work with a single transaction for the whole set of inserts so you can rollback if something fails.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search