Within a particular set of results from a query, I want to number the lines, e.g. Order 1 has 5 lines, I want to process the results to read
Order 1,0
Order 1,1
Order 1,2
Order 1,3
Order 1,4
I am using the following code to achieve this, but I can't seem to get it to work. I am getting the 2 errors:
Here is my code snippet:
Thanks in advance,
Donald
Order 1,0
Order 1,1
Order 1,2
Order 1,3
Order 1,4
I am using the following code to achieve this, but I can't seem to get it to work. I am getting the 2 errors:
Code:
Cannot resolve the collation conflict between
Code:
Ambiguous Column 'RecordKey'
Here is my code snippet:
Code:
DECLARE @RecordKey varchar(100)
DECLARE @NumAtCard AS NVARCHAR(20)
SET @NumAtCard = (Select max(T0.NumAtCard) FROM OINV T0 WHERE T0.Series = '37' and T0.NumAtCard not like '500%')
SELECT T0.RecordKey,T0.LineNum,T0.ItemCode,T0.LineTotal,T0.Price,T0.Quantity,T0.TaxCode,T0.TaxLiable,T0.WarehouseCode,
'3' as SalesPersonCode,0 as processed
INTO ##orderlines
FROM dbo.[@GoorinWEBOrderLines] T0
WHERE T0.RecordKey > @NumAtCard
ORDER BY RecordKey ASC
CREATE TABLE ##orderlines_2(LineNum Int Identity(0,1), RecordKey varchar(100))
WHILE (SELECT count(*) FROM ##orderlines WHERE processed = 0) > 0
BEGIN
CREATE TABLE ##orderlines_1 (RecordKey varchar(100))
INSERT INTO ##orderlines_1(RecordKey)
SELECT TOP 1 isnull(RecordKey,'')
FROM ##orderlines
WHERE processed = 0
INSERT INTO ##orderlines_2(RecordKey)
SELECT RecordKey
FROM ##orderlines T0 INNER JOIN ##orderlines_1 T1 ON T0.RecordKey = T1.RecordKey
SELECT TOP 1 @RecordKey = isnull(RecordKey,'')
FROM ##orderlines_1
UPDATE ##orderlines set processed = 1 where RecordKey = @RecordKey
DROP TABLE ##orderlines_1
END
Thanks in advance,
Donald