BCh
Posts: 63
Joined: Wed Jan 17, 2007 6:32 am
Location: Australia

Server SQL Databases Inline Script Questions

Hi,

Have some questions re the use of SQL scripting under Server | SQL Databases \ Database server | Predefined Connection | SQL script | New SQL Script File.

Use of Statement separator.
I really do not understand the statement " during installation the QQL script file will be automatically split into component statements using the supplied statement separator and each SQL statement will be executed individually. Otherwise the SQL script will be executed as a whole."

I have a script that is something like:

Declare @variable bit
Set @variable = 1;

If (db exists) -- do this since could be updating over an existing sql db and need to store customer data somewhere
begin
run a bat file using bcp -- this exports rows in tables to dat file
drop database
set @variable = 0
end

if (db not exists) --which it won't of course but could be and initial install
begin
restore db --this is an updated data base
end

--do some other sql stuff!!!

if @variable = 0 --means have customer data so need to import into
begin
run a bat file using bcp that imports created dat file above
end

No matter what I set statement separator to or update the script to include GO statements after each SQL command the log file only shows that the first "if (db exists)" statement is executed and anything after that is ignored.


I could break each statement into separate SQL scripts but not sure how to do the last step which is based on a variable updated in step one.



Thanks,
Brian
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Server SQL Databases Inline Script Questions

Hello Brian,

In your case you should NOT use any separator. Just leave the "Statement Separator" field empty and let us know if this helps.

Basically you should write your script exactly as you write it in SQL Server Management Studio IDE when you test it.

Let us know if this helped.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”