Skip to content

Instantly share code, notes, and snippets.

@MachinesAreUs
Created September 6, 2012 12:40
Show Gist options
  • Save MachinesAreUs/3655847 to your computer and use it in GitHub Desktop.
Save MachinesAreUs/3655847 to your computer and use it in GitHub Desktop.
Example for creating SQL script from a templat in Ruby
require 'fileutils'
require 'erb'
template = ERB.new <<-EOF
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'<%= sp_name %>') AND type in (N'P', N'PC'))
DROP PROCEDURE <%= sp_name %>
GO
EOF
File.readlines('sps_to_delete.txt').each do |line|
sp_name = line.chomp
puts template.result(binding)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment