Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select data from different database

Author  Topic 

Apples
Posting Yak Master

146 Posts

Posted - 2009-11-10 : 12:07:20
I'm having trouble with creating a view Here's my query:


USE [011-ShoppingCart]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_Orders]
AS

SELECT O.OrderID, U.Username,
(SELECT COUNT(*) FROM 011-OtherDB.dbo.tblSyncData WHERE Username = U.Username) AS OrderCount

FROM tblOrders O INNER JOIN tblUsers U ON O.UserID = U.UserID


I'm getting this error: " Incorrect syntax near '011' "

If I remove the numbers from the front of the database name, it works correctly. How can I fix this?

I'm using SQL Server 2005.

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-10 : 12:24:33
do you have a database named 011-OtherDB?

If yes, maybe use

FROM [011-OtherDB].[dbo].[tblSyncData]


????



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-10 : 12:41:45
and i hope both of dbs are in same server instance
Go to Top of Page
   

- Advertisement -