OldSlowDog
Programmer
I am working on a project that I have to select the same table from each store and say, print a report with the query results. I am trying to use just one Stored Procedure by passing differnet city name to it.
The problem is that I can't swtich from db to db. I tried DECLARE @City in different ways. they all failed. Please help.
I tried and failed:
DECLARE @City
SET @City = 'Phoenix'
SELECT * FROM @City.dbo.SalesTbl
I also tried and failed:
DECLARE @City
SET @City = 'Phoenix'
USE @City
SELECT * FROM SalesTbl
The SQL Server setup:
XYZEnterprise(SQL Server 9.0.4035)
DataBases
Phoenix
Dallas
SaltLake
SanAntonio
Thanks for helping
The problem is that I can't swtich from db to db. I tried DECLARE @City in different ways. they all failed. Please help.
I tried and failed:
DECLARE @City
SET @City = 'Phoenix'
SELECT * FROM @City.dbo.SalesTbl
I also tried and failed:
DECLARE @City
SET @City = 'Phoenix'
USE @City
SELECT * FROM SalesTbl
The SQL Server setup:
XYZEnterprise(SQL Server 9.0.4035)
DataBases
Phoenix
Dallas
SaltLake
SanAntonio
Thanks for helping