December 27, 2009 at 7:59 pm
Row_id_no is the column.
This is the code
SELECT max(DWT40034_BZL_VAT_TAX.ROW_ID_NO)
from (select DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD, DWT40034_BZL_VAT_TAX.ORD_LN,
max(DWT40034_BZL_VAT_TAX.INTGRT_SRC_TRX_DT)
from dbo.DWT40034_BZL_VAT_TAX
where DWT40034_BZL_VAT_TAX.ETL_PROC_STAT = 1
group by DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD, DWT40034_BZL_VAT_TAX.ORD_LN)
Error Report
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ')'.
December 27, 2009 at 8:07 pm
a subselect in parenthesis must have an alias;
formatting helps identiy the problem, too:
SELECT
max(DWT40034_BZL_VAT_TAX.ROW_ID_NO)
from
(
select
DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD,
DWT40034_BZL_VAT_TAX.ORD,
DWT40034_BZL_VAT_TAX.ORD_LN,
max(DWT40034_BZL_VAT_TAX.INTGRT_SRC_TRX_DT)
from dbo.DWT40034_BZL_VAT_TAX
where DWT40034_BZL_VAT_TAX.ETL_PROC_STAT = 1
group by DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD, DWT40034_BZL_VAT_TAX.ORD_LN
) MyAlias
Lowell
December 27, 2009 at 8:12 pm
I tried the code you gave, but got error
Msg 8155, Level 16, State 2, Line 1
No column was specified for column 4 of 'MyAlias'.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "DWT40034_BZL_VAT_TAX.ROW_ID_NO" could not be bound.
I tried this also
SELECT
max(MyAlias.ROW_ID_NO)
from
(
select
DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD,
DWT40034_BZL_VAT_TAX.ORD,
DWT40034_BZL_VAT_TAX.ORD_LN,
max(DWT40034_BZL_VAT_TAX.INTGRT_SRC_TRX_DT)
from dbo.DWT40034_BZL_VAT_TAX
where DWT40034_BZL_VAT_TAX.ETL_PROC_STAT = 1
group by DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD, DWT40034_BZL_VAT_TAX.ORD_LN
) MyAlias
But didn't work
Msg 8155, Level 16, State 2, Line 1
No column was specified for column 4 of 'MyAlias'.
Msg 207, Level 16, State 1, Line 2
Invalid column name 'ROW_ID_NO'.
December 27, 2009 at 8:29 pm
the error message is the clue: you can't select the row_id_no, because it is not part of the subquery in parenthesis.
remember what i said about aliases and parenthesis? that goes for MIN()/MAX()/SUM() functions as well
SELECT
max(MyAlias.ROW_ID_NO)
from
(
select
DWT40034_BZL_VAT_TAX.ROW_ID_NO,
DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD,
DWT40034_BZL_VAT_TAX.ORD,
DWT40034_BZL_VAT_TAX.ORD_LN,
max(DWT40034_BZL_VAT_TAX.INTGRT_SRC_TRX_DT) AS MYDATE
from dbo.DWT40034_BZL_VAT_TAX
where DWT40034_BZL_VAT_TAX.ETL_PROC_STAT = 1
group by DWT40034_BZL_VAT_TAX.ROW_ID_NO,DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD, DWT40034_BZL_VAT_TAX.ORD_LN
) MyAlias
Lowell
December 27, 2009 at 8:39 pm
Ok i got it
Thank you very much
December 27, 2009 at 8:53 pm
Can i write like this
SELECT VAT_TAX.ROW_ID_NO = (max(DWT40034_BZL_VAT_TAX.ROW_ID_NO)
from (select
DWT40034_BZL_VAT_TAX.ROW_ID_NO,
DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD,
DWT40034_BZL_VAT_TAX.ORD,
DWT40034_BZL_VAT_TAX.ORD_LN,
max(DWT40034_BZL_VAT_TAX.INTGRT_SRC_TRX_DT) as Mydate
from dbo.DWT40034_BZL_VAT_TAX
where DWT40034_BZL_VAT_TAX.ETL_PROC_STAT=1
group by DWT40034_BZL_VAT_TAX.ROW_ID_NO, DWT40034_BZL_VAT_TAX.INTGRT_CNTRY_CD, DWT40034_BZL_VAT_TAX.ORD,
DWT40034_BZL_VAT_TAX.ORD_LN))VAT_TAX
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply