May 5, 2005 at 1:16 am
Hi Gurus,
I have written a small piece of code to get the database name in QA whenever I execute it. Now I specified northwind, so in QA it shude becum northwind. The code executes successfully, but the database does not change to the database mentioned.
declare @DB nvarchar(10)
declare @DB1 nvarchar(20)
set @DB = 'northwind'
set @db1 = 'use ' + @Db
print @db1
exec (@db1)
Any ideas ?
--Kishore
May 5, 2005 at 6:24 am
Without a [GO] you would need to include any additional commands in @db1 seperated by [;]. It's context did switch but returns to your current db after execution.
May 5, 2005 at 6:29 am
I dont understand your solution can u send a modified code with what u are trying to suggest us.
May 5, 2005 at 6:59 am
use pubs
go
select top 10 * from northwind..customers
declare @DB nvarchar(10)
declare @DB1 nvarchar(2000) -- INCREASED SIZE
set @DB = N'northwind'
set @db1 = N'use ' + rtrim(@Db)+'; update customers set ContactName = rtrim(ContactName)+'' XXX'' where CustomerID = ''ALFKI''' -- anything you want to do here
-- otherwise you'll have to switch to the correct db in your script prior to going dynamic
-- the [GO] will drop any previously defined variables
-- and those are multiple single quotes not double quotes
print @db1
exec (@db1)
select top 10 * from northwind..customers
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply