sql server - Creating stored procedure in another database -


Any idea is possible to create a process in other databases using T-SQL alone, where the database's Is not the name going to be front and read from a table? Like this example:

  Use [Master Database] Announce @firstdatabase Enchantment (100) Select Top 1 @ FirstDatabase = [Childdates] [Announcement] [from Child Database] @SQL NewWorker (4000 ) Please declare @CRLF Nvarchar (10) set @ CRLF = nchar (13) + nchar (10) set @squal = '[[' 'FirstDatabase +'] '+ @CRLF +' Go '+ @CRLF + Select '123 like make' test 'Exec (@sQL)  

See what I want to do I am doing? This example fails because go is not actually a T-SQL command but it is recognized by some query analyzer / SQL Management Studio and generates an error. Remove Go and it also fails because Prok should make the first line of the script. Arrgg!

The syntax of T-SQL does not allow you to work in this way:

Create [other database]. [DBO]. [Test]

It's a shame because it will work as a treatment! You can choose that this is incompatible with the statements:

Choose [from other database] .. [TheTable]

Cheers, Rob.

This is a pain, but this is what I do. I got it with an example in which I found on Scaltam, I think - I have some quoted issues with whom I am indiscriminately REPLACE :

  DECLARE @sql AS Varchar (MAX) DECLARE @metasql varchar (MAX) DECLARE as Start @ bit as display @ bit display as bit as SET @PrintQuery = 1 SET @ExecQuery = 0 SET @sql = 'Presentation etc. Start 'SET @ METASCAL =' USE Other Database EXEC ('' '+ + REPLACE (@sql,' '' '' '' ') +' '' @ PrintContent = 1 Print @ MetasCal if @ExecQuery = 1 EXEC (@MAMASCAL)  

Comments