Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to retreive data from three table based on common fields in sql 2008?

$
0
0

Hi every body,

I have three table as follow:

CREATETABLE [dbo].[hesab_moin](

     [id] [int] IDENTITY(1,1)NOTNULL,

     [id_moin] [int] NOT NULLprimarykey,

     [id_kol] [int] NOT NULL,

     [type_hesab] [nvarchar](70)NOTNULL,

     [moin_name] [nvarchar](70)NOTNULL,

     [id_sath_4] [nvarchar](120)NULL,

     [id_sath_5] [nvarchar](120)NULL,

     [id_sath_6] [nvarchar](120)NULL,

     [hesab_state] [bit] NOT NULL)

GO      

CREATETABLE [dbo].[hesab_tafzili](

     [id_tafzili] [int] IDENTITY(1,1)NOTNULL primarykey,

     [code] [int] NOT NULL,

     [caption] [nvarchar](70)NOTNULL,

     [company_type] [nvarchar](70)NULL,

     [ekhtesar_name] [nvarchar](70)NULL,

     [kode_ekhtesadi] [nvarchar](70)NULL,

     [shenase_meli] [nvarchar](70)NULL,

     [onvan_latin] [nvarchar](70)NULL,

     [name_latin] [nvarchar](70)NULL,

     [sath] [nvarchar](70)NULL,

     [id_moin] [int] NOT NULL)

GO

CREATETABLE [dbo].[sanad_hesabdari](

     [id] [int] IDENTITY(1,1)NOTNULL primarykey,

     [id_sanad] [int] NOT NULL,

     [id_moin] [int] NOT NULL,

     [kod_tafzil] [int] NULL,

     [sathe_4] [nvarchar](70)NULL,

     [sathe_5] [nvarchar](70)NULL,

     [sathe_6] [nvarchar](70)NULL,

     [sharh] [nvarchar](120)NULL,

     [bed] [bigint] NULL,

     [bes] [bigint] NULL,

     [arz_name] [nvarchar](20)NULL)

GO

This is my query :

SELECTa.id_moin,b.id_moin,b.code,b.sath,c.id_moin,c.sathe_4,c.sathe_5,c.sathe_6,c.sharh,c.bed,c.bes,c.arz_name,c.id_sanadfromhesab_moin a,hesab_tafzili b,sanad_hesabdari cwherea.id_moin = b.id_moin and a.id_sath_4 = b.sath and a.id_sath_5 = b.sath and a.id_sath_6 = b.sath

I want retreive 'id_moin' from 'hesab_moin' into combobox inside 'id_moin' field of 'sanad_hesabdari' table and also 'sath' field of 'hesab_tafzili' table into combobox inside 'sathe_4' and ' sathe_5' and 'sathe_6' fields of 'sanad_hesabdari' table, so that with selecting 'c.id_moin' into 'sanad_hesabdari' table, defined records of each 'b.sath' display only inside own combobox.

it is not work fine.

pls help me.

best regards.

 


Viewing all articles
Browse latest Browse all 23857

Trending Articles