如果有人能夠完全將此T-SQL查詢轉換爲SAP HANA,我將很高興。將T-SQL查詢更改爲SAP HANA
我想要做的是自動編號具有PV加6個數字前綴的查詢。例如pv000001。我在T-SQL中使用它,但我有一個挑戰,完全將其更改爲SAP HANA;
DECLARE @NumRange integer;
SET @NumRange := 6;
SELECT 'PV' || replicate('0', @NumRange - LENGTH(MAX(ISNULL(Incnum, 0)))) || CAST(MAX(ISNULL(Incnum, 0)) + 1 AS varchar(6))
FROM (
SELECT MAX(coalesce(substring(CounterRef, 3, LENGTH(ISNULL(CounterRef, 0))), 0)) AS "incnum"
FROM OVPM T0
UNION ALL
SELECT MAX(coalesce(substring(CounterRef, 3, LENGTH(ISNULL(CounterRef, 0))), 0)) AS "incnum"
FROM OPDF T0 WHERE t0.ObjType = '46'
) AS Tb1;
[編輯]你的問題,並添加基於該數據的一些樣本數據和預期輸出。 [_Formatted_](http://stackoverflow.com/editing-help#code)**文本**,請[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i -not-upload-images-code-on-so-when-asking-question-285557#285557) –
你不能簡單地使用'row_number()'來產生數字嗎? –