September 12, 2013 at 1:25 pm
CREATE TABLE [dbo].[A](
[ID] [smallint] NOT NULL,
Name nvarchar(10),
[AssocTableName] [nvarchar](50) NULL,
data:
1 TableType AssociatedTable1
CREATE TABLE [dbo].[AssociatedTable1](
[ID] [smallint] NOT NULL,
[Desc] [nvarchar](80) NULL,
data: 1 Supp 2 Sup2
Is there any way i can join these two tables?
September 12, 2013 at 1:50 pm
I don't see any relationship between these two tables.
Is it that in your Table A, you are maintaining list of Tables
and AssociatedTable1 is an another table for which there will be an entry in Table A.
Is it correct?
September 12, 2013 at 1:52 pm
The relationship stems through the Associated Table so the associated table has the corresponding values for the first table. Did that answer your question ?
September 12, 2013 at 1:54 pm
SQLTestUser (9/12/2013)
The relationship stems through the Associated Table so the associated table has the corresponding values for the first table. Did that answer your question ?
Not really, it's too vague. Which columns match?
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
September 12, 2013 at 2:00 pm
well none of the columns explicity match each other. the table A stores the name of the associated table name.
[AssocTableName] [nvarchar](50) NULL stores the name for the associated table
data:
1 TableType AssociatedTable1
CREATE TABLE [dbo].[AssociatedTable1](
[ID] [smallint] NOT NULL,
[Desc] [nvarchar](80) NULL,
data: 1 Supp
2 Sup2
3 Sup3
4 sup4
the data for both is stored in a third table as
CREATE TABLE [dbo].[FinalStore](
[ID] [smallint] NOT NULL, -- this Id is from Table A
[Desc] [nvarchar](80) NULL, -- this Desc is from the associated table
as
TableType Supp
September 12, 2013 at 2:28 pm
Do you need to create the third table by querying first two tables?
September 12, 2013 at 2:32 pm
no i am trying to connect these three table
September 12, 2013 at 2:55 pm
What you have is a painful twist to an EAV type of system. This is going to be nothing but slow, tedious and nightmarish as the system gets larger.
We can help you figure out how to query this but we will need a few things:
1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data
Please take a few minutes and read the first article in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 12, 2013 at 4:15 pm
Sample DDL in the form of CREATE TABLE statements
CREATE TABLE [dbo].[FinalStore1](
[AID] [smallint] NULL,
[AssociatedTableID] [smallint] NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[StoreAssociatedTable1](
[AID] [smallint] NULL,
[AName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AssociatedTableName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
CREATE TABLE [dbo].[AssociatedTable2](
[AssociatedTableID] [smallint] NULL,
[Desc] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
2. Sample data in the form of INSERT INTO statements
INSERT [dbo].[AssociatedTable2] ([AssociatedTableID], [Desc]) VALUES (1, N'ThisExample')
INSERT [dbo].[AssociatedTable2] ([AssociatedTableID], [Desc]) VALUES (2, N'ThisStore')
INSERT [dbo].[StoreAssociatedTable1] ([AID], [AName], [AssociatedTableName])
VALUES (1, N'StoreValues', N'AssociatedTable1')
INSERT [dbo].[StoreAssociatedTable1] ([AID], [AName], [AssociatedTableName])
VALUES (2, N'MerchantValues', N'AssociatedTable1')
INSERT [dbo].[FinalStore1] ([AID], [AssociatedTableID]) VALUES (1, 1)
3. Expected results based on the sample data
A join that would show the values as:
1)The values for StoreValues are ThisExample,ThisStore
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply