Home All Groups Group Topic Archive Search About
Author
12 Aug 2006 7:05 AM
gold.study@gmail.com
Hi everybody.

I have 2 tables named daily, executive

Structure of Executive :
exe_code - nvarchar(20)
exe_name - nvarchar(100)

Structures of Daily:

fileno - int identity(1,1)
name - nvarchar(20)
resiexecode - nvarchar(20)
offexecode - nvarchar(20)

Records in Executive :

exe01 - Ram
exe02 - Gold
exe03 - King
exe04 - Vincent

Records in Daily :

101    Customer1      exe01     exe01
102    Customer2      exe02     exe01
103    Customer3      exe01     exe02
104    Customer4      exe03     exe04
105    Customer5      exe04     exe02


I want report as :

101    Customer1      Ram       Ram
102    Customer2      Gold       Ram
103    Customer3      Ram       Gold
104    Customer4      King       Vincent
105    Customer5      Vincent   Gold


Please send me a suitable query to sonlve this Problem


Thanks in advance..

Warm Reagrds
Goldking

Author
12 Aug 2006 7:18 AM
David Portas
gold.st***@gmail.com wrote:
Show quote
> Hi everybody.
>
> I have 2 tables named daily, executive
>
> Structure of Executive :
> exe_code - nvarchar(20)
> exe_name - nvarchar(100)
>
> Structures of Daily:
>
> fileno - int identity(1,1)
> name - nvarchar(20)
> resiexecode - nvarchar(20)
> offexecode - nvarchar(20)
>
> Records in Executive :
>
> exe01 - Ram
> exe02 - Gold
> exe03 - King
> exe04 - Vincent
>
> Records in Daily :
>
> 101    Customer1      exe01     exe01
> 102    Customer2      exe02     exe01
> 103    Customer3      exe01     exe02
> 104    Customer4      exe03     exe04
> 105    Customer5      exe04     exe02
>
>
> I want report as :
>
> 101    Customer1      Ram       Ram
> 102    Customer2      Gold       Ram
> 103    Customer3      Ram       Gold
> 104    Customer4      King       Vincent
> 105    Customer5      Vincent   Gold
>
>
> Please send me a suitable query to sonlve this Problem
>
>
> Thanks in advance..
>
> Warm Reagrds
> Goldking


Try this (untested):

SELECT D.fileno, D.name,
E1.exe_name AS exe_name1,
E2.exe_name AS exe_name2
FROM Daily AS D
JOIN Executive AS E1
  ON D.resiexecode = E1.exe_code
JOIN Executive AS E2
  ON D.offexecode = E2.exe_code ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Author
12 Aug 2006 9:06 AM
gold.study@gmail.com
Thanks alot.. It is fine Now..

Now i have one more problem as:

Records in Daily :

101    Customer1      exe01     exe01
102    Customer2      exe02     exe01
103    Customer3      exe01     exe02
104    Customer4      exe03     exe04
105    Customer5      exe04     exe02
106    Customer4      exe03     null
107    Customer5      null         null

I want report as :

101    Customer1      Ram       Ram
102    Customer2      Gold       Ram
103    Customer3      Ram       Gold
104    Customer4      King       Vincent
105    Customer5      Vincent   Gold
106    Customer4      King
107    Customer5

How i get this type of report..

Thanks a lot...

Warm Regards

Goldking



David Portas wrote:
Show quote
> gold.st***@gmail.com wrote:
> > Hi everybody.
> >
> > I have 2 tables named daily, executive
> >
> > Structure of Executive :
> > exe_code - nvarchar(20)
> > exe_name - nvarchar(100)
> >
> > Structures of Daily:
> >
> > fileno - int identity(1,1)
> > name - nvarchar(20)
> > resiexecode - nvarchar(20)
> > offexecode - nvarchar(20)
> >
> > Records in Executive :
> >
> > exe01 - Ram
> > exe02 - Gold
> > exe03 - King
> > exe04 - Vincent
> >
> > Records in Daily :
> >
> > 101    Customer1      exe01     exe01
> > 102    Customer2      exe02     exe01
> > 103    Customer3      exe01     exe02
> > 104    Customer4      exe03     exe04
> > 105    Customer5      exe04     exe02
> >
> >
> > I want report as :
> >
> > 101    Customer1      Ram       Ram
> > 102    Customer2      Gold       Ram
> > 103    Customer3      Ram       Gold
> > 104    Customer4      King       Vincent
> > 105    Customer5      Vincent   Gold
> >
> >
> > Please send me a suitable query to sonlve this Problem
> >
> >
> > Thanks in advance..
> >
> > Warm Reagrds
> > Goldking
>
>
> Try this (untested):
>
> SELECT D.fileno, D.name,
>  E1.exe_name AS exe_name1,
>  E2.exe_name AS exe_name2
>  FROM Daily AS D
>  JOIN Executive AS E1
>   ON D.resiexecode = E1.exe_code
>  JOIN Executive AS E2
>   ON D.offexecode = E2.exe_code ;
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
Author
12 Aug 2006 10:21 AM
David Portas
gold.st***@gmail.com wrote:

Show quote
> Thanks alot.. It is fine Now..
>
> Now i have one more problem as:
>
>  Records in Daily :
>
>  101    Customer1      exe01     exe01
>  102    Customer2      exe02     exe01
>  103    Customer3      exe01     exe02
>  104    Customer4      exe03     exe04
>  105    Customer5      exe04     exe02
>  106    Customer4      exe03     null
>  107    Customer5      null         null
>
>  I want report as :
>
>  101    Customer1      Ram       Ram
>  102    Customer2      Gold       Ram
>  103    Customer3      Ram       Gold
>  104    Customer4      King       Vincent
>  105    Customer5      Vincent   Gold
>  106    Customer4      King
>  107    Customer5
>
> How i get this type of report..
>
> Thanks a lot...
>
> Warm Regards
>
> Goldking
>
>

Please do NOT post the question independently to multiple groups. Your
question has nothing to do with Setup so why post the same question
there? If you don't know how to do cross-posting instead of
mult-posting then refer to the documentation for your news client.

Change JOIN to LEFT OUTER JOIN. Lookup COALESCE / ISNULL.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button