Phoenix
Phoenix

Reputation: 41

Altering Three Variables in an SQL File Without Explicitly Opening It

To clarify what my question means and give some context, me and my colleague are working on an msi package (developed using WiX 3.5) that automates the installation and configuration of a terminal with our software. However one point on our tech note indicates that an sql file needs to be opened and changed as per user requirement at the time, so something we cannot hard code in.

Getting the variables we need is no problem, setup can export a settings.ini file or whatever that will hold the values we need, the problem is moving these values directly into an sql file automatically, with as little user interaction as possible. Our client company's workers are not software people, so we need to find a way.

The "SET" parts are the fields that need to be updated on install:

DECLARE @Galaxy varchar(32)
SET @Galaxy = 'foo'
DECLARE @IPAddress varchar(15)
SET @IPAddress = 'foo'
DECLARE @Project varchar(32)
SET @Project = 'foo'

Any insight would be very helpful, SQL is not my usual area of work.

Upvotes: 0

Views: 64

Answers (1)

devio
devio

Reputation: 37205

From your requirements I conclude that SQL Server client needs to be installed on each terminal. Thus sqlcmd is available, and you can use the :setvar mechanism to set values before executing the script.

See this example where :setvar is used directly in the .sql script. Variables are evaluated using $(variablename). These variables can also be set on the command line (section Variable Precedence), so that no modifications in the .sql file are necessary.

Upvotes: 1

Related Questions