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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert coding to t-sql statement

Author  Topic 

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-16 : 02:46:22
Hi all, i think i meet a really big deadlock...wasn't able convert the following clarion language to t-sql statement..any help provided are apprieciate!!!
SELECT	t.st_code, m.st_desc,
SUM(CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.total_price*h.forex_rate END) as SALES,
SUM(CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.qtt_out-t.quantity END) as QUANTITY,
SUM(CASE WHEN t.trx_type <> 'CN' then t.cost_mr else 0 END) as COST,
SUM((CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.total_price*h.forex_rate END)-(CASE WHEN t.trx_type <> 'CN' then t.cost_mr else 0 END)) as MPROFIT,
ISNULL(NULLIF(SUM((CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.total_price*h.forex_rate END)-(CASE WHEN t.trx_type <> 'CN' then t.cost_mr else 0 END)), 0)/NULLIF(SUM(CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.total_price*h.forex_rate END), 0), 0)*100 as MSALES,
ISNULL(NULLIF(SUM((CASE WHEN h.trx_type IN ('CN', 'CNC') then 0 else t.total_price*h.forex_rate END)-(CASE WHEN t.trx_type <> 'CN' then t.cost_mr else 0 END)), 0)/NULLIF(SUM(CASE WHEN t.trx_type <> 'CN' then t.cost_mr else 0 END), 0), 0)*100 as MCOST
FROM st_trx t join (
SELECT trx_type,
forex_code,
CASE WHEN trx_type IN ('DO', 'CDO','DOL') then do_no else in_no END as ref_no,
CASE WHEN forex_rate IS NULL or forex_rate = 0 then 1 else forex_rate end as forex_rate,
CASE WHEN trx_type IN ('DO', 'CDO','DOL') then CASE WHEN in_date IS NULL then do_date else in_date END else in_date END as date
FROM st_head
WHERE trx_type IN('DO','CDO','DOL','INV','CS','CN','DN','POS','INC','CNC')
)h on t.trnx_ref=h.ref_no and t.trx_type=h.trx_type join
(SELECT st_code, st_desc FROM st_mast WHERE st_code >= @startcode and st_code <=@endcode)m on t.st_code = m.st_code
WHERE (h.date >=@startdate and h.date <=@enddate)
GROUP BY t.st_code, m.st_desc
ORDER BY t.st_code

at here i get sales, quantity, cost, msales, mprofit, mcost....the following are coding from Clarion6 [url]http://www.softvelocity.com/[/url], i need to join this 2 thing together
IF STT:TRX_TYPE='CN'
DO GET_CN_COSTgo to the GET_CN_COST function
MAQ:CN_MRCOST += CN_COST_MR
MAQ:CN_WACOST += CN_COST_WA
MAQ:CN_FIFOCOST+= CN_COST_FIFO

ELSE here i solved
MAQ:TOT_MRCOST += STT:COST_MR
MAQ:TOT_WACOST += STT:COST_AVER
MAQ:CN_FIFOCOST+= STT:COST_FIFO

.


GET_CN_COST ROUTINE

CN_COST_MR = 0
CN_COST_WA = 0
CN_COST_FIFO = 0

IF STT:RESERVE1 <>'' AND STT:RESERVE2<>''
TRX_TYPE = STT:RESERVE1
TRNX_REF = STT:RESERVE2
CLEAR(RHI:RECORD)
RHI:TRX_TYPE= TRX_TYPE
RHI:TRX_REF = TRNX_REF
SET(RHI:BY_TRX_REF,RHI:BY_TRX_REF)
LOOP UNTIL ACCESS:RCN_HIS.NEXT()looping RCN_HIS table
IF ERROR() THEN BREAK.
IF RHI:TRX_TYPE <> TRX_TYPE OR RHI:TRX_REF <> TRNX_REF THEN BREAK.

IF RHI:RESERVE1 = STT:TRX_TYPE AND RHI:RESERVE2 = STT:TRNX_REF AND RHI:ST_CODE = STT:ST_CODE

SAV_TRX_TYPE = STT:TRX_TYPE
SAV_TRNX_REF = STT:TRNX_REF
SAV_LINE = STT:LINE
SAV_QTY = STT:QUANTITY

CLEAR(STT:RECORD) !get the original inv and compare the warehouse
STT:TRX_TYPE = RHI:TRX_TYPE
STT:TRNX_REF = RHI:TRX_REF
STT:LINE = RHI:LINE
GET(ST_TRX,STT:BY_TRX_REF)get is like select statement but in here is to find above 3 line
IF ~ERROR()here means found the record
CN_COST_MR = (STT:COST_MR / STT:QTT_OUT) * SAV_QTY
CN_COST_WA = (STT:COST_AVER / STT:QTT_OUT ) * SAV_QTY
CN_COST_FIFO = (STT:COST_FIFO / STT:QTT_OUT ) * SAV_QTY
.

CLEAR(STT:RECORD)
STT:TRX_TYPE = SAV_TRX_TYPE
STT:TRNX_REF = SAV_TRNX_REF
STT:LINE = SAV_LINE
GET(ST_TRX,STT:BY_TRX_REF)

BREAK
.
.
ELSE
!GET COST FROM ST_MAST
CLEAR(STM:RECORD)
STM:ST_CODE = STT:ST_CODE
GET(ST_MAST,STM:BY_ST_CODE)
IF ~ERROR()
CN_COST_MR = STM:COST * STT:QUANTITY
CN_COST_WA = STM:AVER_COST * STT:QUANTITY
.
.

blue colors are the data i wan..but i have no idea how to join these table...
STT: means st_trx table
STM: means st_mast table
RHI: means rcn_his table





Hope can help...but advise to wait pros with confirmation...


Hope can help...but advise to wait pros with confirmation...

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-16 : 04:15:20
i think my question too hard >"<


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-16 : 21:32:37
anyone?


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 21:48:14
Firstly, not everybody knows Clarion. Maybe you can explain what that section of code is doing and what do you need.

Many when see a complex query it will just hit NEXT button . Cause you need to spend more time reading it, understand it before able to provide any advice / helps. After all, we all have our own work to do.

Not sure if it is possible to simplify what you are doing to a simple table with sample data and required result. It will be easier for others to help you.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-16 : 21:55:19
T.T ya i know sifu...so i din't expect much...


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-16 : 21:59:26
but still got hope....


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page
   

- Advertisement -