I do this all the time in SQLCMD mode. Here is an example:
----------------------------- --Generate State seeds ----------------------------- -- This is the path and file where you want the scripts to land. :setvar OutDir "C:\Dev\Sandbox\GenTest\Scripts\" :setvar OutFile "dbo.State.seed.sql" SET NOCOUNT ON; GO :out $(OutDir)$(OutFile) SELECT 'INSERT [State] ([StateId], [StateCd], [Description]) VALUES (' + CAST( [StateId] AS VARCHAR(2)) + ', ''' + [StateCd] + '''' + ', ''' + [Description] + '''' + ');' FROM [State]; GO --this 'GO' is vital for this to work correctly. :out stdout
- Graeme
source share