Author |
Topic |
Yonkouturko
Yak Posting Veteran
59 Posts |
Posted - 2013-04-22 : 02:26:40
|
i have DATABASE1 with ProductTaggtablewith items..SupplierID : Category : Description : Brand and then DATABASE2 with SupplierTablewith Items..SupplierID : SupplierName : Contact Personhow will i ShowSupplierID : SupplierName : Contact Person from DATABASE2:SupplierTableWhile Using DATABASE1 ProductTaggTable as SEARCH REFERENCES:Category or Description Or BrandThank you for your Help!!! :) it will bring peace to my MIND!!!! :) |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-22 : 02:32:25
|
--this?DECLARE @category varchar(10), @description varchar(10), @Brand varchar(10) , SELECT distinct s.*FROM DATABASE2..SupplierTable sJOIN DATABASE1..ProductTaggtable p ON s.SupplierID = p.SupplierIDWHERE Category = @categoryor Description = @descriptionOr Brand = @brand--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-22 : 04:36:57
|
depends on whether databases are on same server or not.If yes, you can use what Bandi suggestedif not, you need to first create a linked server between them seehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=164892then use query likeDECLARE @category varchar(10), @description varchar(10), @Brand varchar(10) , SELECT distinct s.*FROM DATABASE2..SupplierTable sJOIN LINKEDSERVER.DATABASE1..ProductTaggtable p ON s.SupplierID = p.SupplierIDWHERE Category = @categoryor Description = @descriptionOr Brand = @brand ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Yonkouturko
Yak Posting Veteran
59 Posts |
Posted - 2013-04-22 : 08:44:21
|
does it have to have double dots like this"DATABASE1..ProductTaggtable"yes the two databases is on the same server |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-04-22 : 08:57:30
|
You don't necessarily have to have the double-quotes, unless you are using some special characters or reserved keywords. But there is no harm in using them either. But the sytnax is to double-quote each piece of the name as in "DATABASE1"."dbo"."ProductTaggtable". You can also use square brackets [DATABASE1].[dbo].[ProductTaggtable], which is what you will see more often. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-22 : 09:13:17
|
quote: Originally posted by Yonkouturko does it have to have double dots like this"DATABASE1..ProductTaggtable"yes the two databases is on the same server
yesit needs to have double dotsas the order isserver.database.schema.tablehere server being same you'll use db.schema.tableschema you'll leave as blank to assume default schema------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-04-22 : 09:20:10
|
Visakh, thanks! Must be that Monday morning thing, I read "double dots" as "double quotes"!!Note to self: Refrain from driving or operating any heavy machinery until fully awake. |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-22 : 09:21:15
|
You can giveDATABASE1..ProductTaggtableDATABASE1.dbo.ProductTaggtable -- dbo is default schema in SQL ServerDATABASE1.SchemaName.ProductTaggtable -- SchemaName is explicit schema name in which you have that table --Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-22 : 11:56:50
|
quote: Originally posted by bandi You can giveDATABASE1..ProductTaggtableDATABASE1.dbo.ProductTaggtable -- dbo is default schema in SQL ServerDATABASE1.SchemaName.ProductTaggtable -- SchemaName is explicit schema name in which you have that table --Chandu
and they always dont mean the same based on what the logged users default schema is------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|