PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > join with table on another database not working
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
join with table on another database not working

Réponse
 
LinkBack Outils de la discussion
Vieux 09/12/2007, 22h37   #1
Santi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut join with table on another database not working

Hi,

I have two databases on the same server: COMU0002 and 2007DU
and two tables: tecnicos on COMU0002 and telf_cli ON 2007DU

Being on COMU0002 this query doesn't work:

SELECT * FROM tecnicos
LEFT JOIN 2007DU.dbo.telf_cli
ON ...

The error says: INCORRECT SYNTAX NEAR '2007'

Even this query being on 2007DU fails on management studio:
SELECT * FROM 2007DU.dbo.telf_cli

but SELECT * FROM telf_cli works ok

Any ideas?
Thank you!
  Réponse avec citation
Vieux 10/12/2007, 00h34   #2
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: join with table on another database not working

Santi (santi.serrano@gmail.com) writes:
> I have two databases on the same server: COMU0002 and 2007DU
> and two tables: tecnicos on COMU0002 and telf_cli ON 2007DU
>
> Being on COMU0002 this query doesn't work:
>
> SELECT * FROM tecnicos
> LEFT JOIN 2007DU.dbo.telf_cli
> ON ...
>
> The error says: INCORRECT SYNTAX NEAR '2007'
>
> Even this query being on 2007DU fails on management studio:
> SELECT * FROM 2007DU.dbo.telf_cli
>
> but SELECT * FROM telf_cli works ok


2007DU does not adhere to the rules for regular identifiers, as they
must start with a letter, $ or a hash mark. An identifier cannot start
with a number.

However, in difference to most other languages, SQL permits you to use
about any string as an identifier, if you quote it. So instead say one of:

SELECT * FROM "2007DU".dbo.telf_cli
SELECT * FROM [2007DU].dbo.telf_cli

The former agrees with the ANSI standards, but the brackets is what
is most commonly used in the SQL Server world.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  Réponse avec citation
Vieux 10/12/2007, 13h37   #3
Santi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: join with table on another database not working

It works! Thank you!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h44.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,64033 seconds with 11 queries