Dear all,

I am trying to change the current database with the USE command in a
piece of dynamic SQL (since the database will be determined at run
time). I cannot get this to work. SQL always tells me:

"Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near 'GO'."

My code is as follows:

DECLARE SqlString varchar(4000)

SET SqlString = '
USE DEV_EN
GO'

PRINT SqlString
EXEC (SqlString)

However if I run the output of the print statement it runs fine!

What I really want to do here is to change the database and then
create a trigger, as you cannot create a trigger on a different
database to the current one.

i.e.

SET SqlString = '
USE DEV_EN
GO
CREATE TRIGGER ................'

Any help would be greatly appreciated. Thanks in advance.

Ed