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.
| Author |
Topic |
|
lols
Posting Yak Master
174 Posts |
Posted - 2007-06-15 : 01:36:43
|
| Hi,I have the following tables :TowntowncodetownnameAreaareanoareanametowncode Localitylocno(pk)areano(pk)RequestTypereqidreqdtlsEg:1 - Addition2 - Removal3 - RelocateWebSummitSummitIdRequestorNameDateOfRequestreqidAreanoLocNoA Town has areas, Areas have locality so...I want to find out the Town/Area/Locality wise Addition/Removal/Relocation request that have comeduring the last 1 month.The query I have written so far is as follows :SELECT WebRequest.SummitId, RequestType.reqdtls, Area.areaname, Locality.locno, Town.townnameFROM RequestType INNER JOIN WebRequest ON RequestType.reqid = WebRequest.reqid INNER JOIN Area ON WebRequest.areano = Area.areano INNER JOIN TownList ON Area.towncode = TownList.towncode INNER JOIN Locality ON Area.areano = Locality.areanoHowever the results are entirely incorrect with a lot of duplicates.Kindly suggest me the right queryHere's some sample data Town TownCode TownName1 Conteck AreaAreaNo AreaName TownCode1 Area1 12 Area2 13 Area 3 14 Area4 15 Area5 16 Area6 17 Area7 1Locality LocNo AreaNo1 12 13 11 22 21 32 33 34 31 42 41 52 53 5 RequestType reqid reqdtls1 Addition2 Removal3 Relocate WebSummitSummitId RequestorName DateOfRequest reqid AreaNo LocNo1 John 12/6/2007 1 1 12 Jack 13/6/2007 1 1 13 Bill 12/6/2007 2 2 14 Ben 12/6/2007 2 2 25 Dale 14/6/2007 2 3 26 Evjen 15/6/2007 3 1 37 Fuller 16/6/2007 1 4 18 Jimmy 16/6/2007 3 4 29 Kart 16/6/2007 1 5 210 Fuller 16/6/2007 1 5 3Thanks,Vids |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-15 : 08:10:08
|
| try something like this, I don't know how to get the localtime at the momentSELECT t.TownCode, a.AreaNo, w.DateOfRequest FROM Town as t, Area as a, WebSummit as wWHERE t.TownCode = a.TownCodeAND a.AreaNo = w.AreaNoAND datediff(m, localtime, time month ago) < 1 |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2007-06-15 : 08:28:44
|
| Thanks Nowy,I need the locality also in the query.It has to be Town/Area/Locality wise Addition/Removal/Relocation request.I am not too worried about the date. I have figured that out. However in my query, whenever I add the locality, the data gets duplicated. The same happened in my query too.Please suggest.Thanks. |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-15 : 08:35:21
|
| Maybe you can use "SELECT DISTINCT"? |
 |
|
|
lols
Posting Yak Master
174 Posts |
Posted - 2007-06-15 : 14:25:45
|
| I had tried adding the DISTINCT clause. It doesnt work.However I think i got the answer on a different forum.So thanks anyways. |
 |
|
|
|
|
|
|
|