| Author |
Topic |
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 08:01:21
|
| Hi.I trying to get some help building an sql statement for the follwing cenario :I have the following tables :W1A0 ( custumer general data )====CLIENT_REFERENCELAST_NAME_COY_NAMEFIRST_NAMEMIDDLE_NAMESW1V0 ( customer extra data )====CLIENT_REFERENCEMARITAL_STATUSFISCAL_NUMBERBIRTH_DATESEXOCCUPATION_CODEW1L0 ( customer address data )====CLIENT_REFERENCEADDRESS_CATEGORYADDRESS_LINE_1ADDRESS_LINE_2TOWN_SUBURBPOST_CODEI would like to get all my customers W1A0 data, all my customers W1V0 data and the W1L0 data that as the max TIMESTAMP-UPDATED from customer that matches the W1A0 customer.can you help me ? thanks |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-29 : 08:22:07
|
| Where is the TIMESTAMP-UPDATED column ?PBUH |
 |
|
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 08:27:38
|
| sorry. is in the W1L0 table ( address data ). it can return several and what I wish is the latest.regards. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-29 : 08:39:26
|
| [code]select * from(select *,row_number()over(partition by W1A0.CLIENT_REFERENCE order by W1L0.TIMESTAMP-UPDATED desc)rid from W1A0 inner join W1V0 on W1V0.CLIENT_REFERENCE=W1A0.CLIENT_REFERENCEinner join W1L0 on W1L0.CLIENT_REFERENCE=W1A0.CLIENT_REFERENCE)T where rid=1[/code] PBUH |
 |
|
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 08:56:00
|
| thanks for the fast reply.I've run the statement but I'm getting erro : SQL CODE IS -104 DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL ",". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: FROM INTO DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR DSNT416I SQLERRD = 502 0 0 -1 24 0 SQL DIAGNOSTIC INFORMATION DSNT416I SQLERRD = X'000001F6' X'00000000' X'00000000' X'FFFFFFFF' X'00000018' X'00000000' SQL DIAGNOSTIC INFORMATION This is in sql for the DB2 of IBM. I don't know if that makes any diference. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-12-29 : 09:00:00
|
| can you show what you want with some sample data?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-29 : 09:04:54
|
quote: This is in sql for the DB2 of IBM. I don't know if that makes any diference.
It does.My query wont work for DB2.PBUH |
 |
|
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 09:50:04
|
| Sachin, Do you know how it can be done for DB2 ?visakh, I'm making the sample. |
 |
|
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 09:54:43
|
| W1A0 ( custumer general data )====CLIENT_REFERENCE LAST_NAME_COY_NAME FIRST_NAME MIDDLE_NAMES1001 Mendes João Sousa1002 Salvador Nuno SilvaW1V0 ( customer extra data )====CLIENT_REFERENCE MARITAL_STATUS FISCAL_NUMBER BIRTH_DATE SEX OCCUPATION_CODE1001 C 12345678 12-12-1990 M 121002 C 87654321 12-12-1980 M 12W1L0 ( customer address data )====CLIENT_REFERENCE ADDRESS_CATEGORY ADDRESS_LINE_1 ADDRESS_LINE_2 TOWN_SUBURB POST_CODE TIMESTAMP_UPDATED1001 X Rua da Palavra Nr 200 Lisboa 12000456 2007-01-01-10.10.10.0000001001 X Rua da Palavra Nr 201 Lisboa 12000456 2008-01-01-10.10.10.0000001001 X Rua da Palavra Nr 202 Lisboa 12000456 2009-01-01-10.10.10.0000001001 X Rua da Palavra Nr 203 Lisboa 12000456 2010-01-01-10.10.10.0000001002 X Rua da Palavra Nr 300 Lisboa 16000456 2007-01-01-10.10.10.0000001002 X Rua da Palavra Nr 301 Lisboa 16000456 2008-01-01-10.10.10.000000 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-12-29 : 09:54:54
|
quote: Originally posted by jorgepeneirol thanks for the fast reply.I've run the statement but I'm getting erro : SQL CODE IS -104 DSNT408I SQLCODE = -104, ERROR: ILLEGAL SYMBOL ",". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: FROM INTO DSNT418I SQLSTATE = 42601 SQLSTATE RETURN CODE DSNT415I SQLERRP = DSNHPARS SQL PROCEDURE DETECTING ERROR DSNT416I SQLERRD = 502 0 0 -1 24 0 SQL DIAGNOSTIC INFORMATION DSNT416I SQLERRD = X'000001F6' X'00000000' X'00000000' X'FFFFFFFF' X'00000018' X'00000000' SQL DIAGNOSTIC INFORMATION This is in sql for the DB2 of IBM. I don't know if that makes any diference.
then you need to post it on DB2 forum. this is MS SQL Server forum------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jorgepeneirol
Starting Member
6 Posts |
Posted - 2010-12-29 : 09:56:02
|
| sorry, ok thanks for your help. I'm going to an DB2 Forum. regards. |
 |
|
|
|