Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with a big query

Author  Topic 

leite333
Starting Member

8 Posts

Posted - 2011-03-12 : 01:39:47
Hi
I want some help to create a big query to get a specific result.
My tables i am interesting too are:
1)E1_Emp001_3 -> Fields: Kwd,Company,Adress_1,City_1,Tel_1,Tel_2,Mobile,Ypol,SinTzirou,KwdPoliti,OnomaPoliti
2)E1_Emp016_3->Fields:
KwdPelati(same with kwd from E1_Emp001_3),KwdPar,DatePar
3)The third Table i dont know if its neccessary its
E1_Emp051_3->Fields:
Kwd(same with KwdPoliti),FullName(same with OnomaPoliti from above)

The result i wanna get is little complicate:
I wanna take for every seller(OnomaPoliti or(FullName) and Kwd(same with KwdPoliti)and City
Customers with: Kwd,Company,Adress_1,Tel_1,Tel_2,Mobile,Ypol,SinTziroy.
Cities maybe the same but with different seller and different customers. The last field i wanna take as a result wich is the most difficult is a field(Mesos) wich will bring as a result counting of days from today now and the last day that E1_Emp016_3.KwdPar was 1 or 3.
AS far i have made that query but is not the best:
SELECT row_number() OVER (ORDER BY KWDPWLITI, CITY_1) AS Row_No ,
E1_Emp051_3.FULLNAME,
E1_Emp001_3.CITY_1,
E1_Emp001_3.KWDPWLITI,
E1_Emp001_3.TEL_1,
E1_Emp001_3.TEL_2,
E1_Emp001_3.COMPANY,
E1_Emp001_3.PRYPOL,
E1_Emp001_3.SINTZIROU,
E1_EMP016_3.KWDPAR,
DATEDIFF(DAY,DATEPAR,GETDATE()) AS MESOS

FROM E1_Emp001_3, E1_Emp051_3,E1_Emp016_3

WHERE E1_Emp051_3 .KWD = E1_Emp001_3.KWDPWLITI

Please help..



   

- Advertisement -