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.
| Author |
Topic |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-03-14 : 16:17:47
|
Do anyone know of an easy way to load the contents of a SQL script file into a NVARCHAR(MAX) column in a table?It would be very handy to be able to do this so I can have SQL scripts loaded in a table and then execute them from a job.Declare @MyScript nvarchar(max)select @MyScript = MyScript from MyScriptTable where ScriptName = ‘MySQLScript’execute ( @MyScript ) CODO ERGO SUM |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-03-14 : 16:48:24
|
| Try this:INSERT INTO SomeTable(Column1)EXEC master.dbo.xp_cmdshell 'type c:\SomeScriptFile.txt'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-03-14 : 17:12:04
|
quote: Originally posted by tkizer Try this:INSERT INTO SomeTable(Column1)EXEC master.dbo.xp_cmdshell 'type c:\SomeScriptFile.txt'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/
The xp_cmdshell output returns multiple rows, so that isn't really what I need.I want to be able to put the script into a single column of a single row of a table.CODO ERGO SUM |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-03-14 : 17:37:13
|
| I'm pretty sure that you are going to have to do like I showed and put it into a staging table and then move your data to your actual table in the way that you want it. You'll probably need to concatenate each row together to get it into one row, one column.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
|
|
|
|