on 07-14-2011 3:37 PM
Experts,
BP - V00000000000001 - V00000000001315 - Last No. Vendor
BP - C00000000000001 - C00000000039861 - Last No. Customer
Item - 1000000001 - 1000016632 - Last No.
For generating auto code for this
SELECT
CASE $[$40.0]
When 'C' then 'C
'When 'L' then 'L'
When 'S' then 'V'
ENDIsnull(Substring(Str(100000Max(Right(T0.CardCode,5))+1,6),2,5),'00001')
FROM OCRD T0
WHERE T0.CardCode like '%[0-9][0-9][0-9][0-9][0-9]'AND T0.CardType = $[$40.0]
I am using this, am i going right? it is not giving any value...
Hi Rupa,
The following should give you what you need.
DECLARE @NextNumber INT
SELECT @NextNumber = ISNULL(MAX(CAST(RIGHT(T0.CardCode, LEN(T0.CardCode) - 1) AS INT)), 0) + 1
FROM OCRD T0
WHERE ISNUMERIC(RIGHT(T0.CardCode, LEN(T0.CardCode) - 1)) = 1
AND T0.CardType = $[$40.0.0]
SELECT
CASE $[$40.0.0]
WHEN 'S' THEN 'V'
ELSE $[$40.0.0]
END + REPLICATE('0', 14-LEN(CAST(@NextNumber AS NVARCHAR))) + CAST(@NextNumber AS NVARCHAR)
This will return a 15 character code of the appropriate prefix and number. It also dynamically adjusts to the length of the next number rather than hard coding the zeros into the formula.
Hope this helps.
Cheers,
Sean
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
SELECT
CASE $[$40.0]
When 'C' then 'C'
When 'L' then 'L'
When 'S' then 'V'
END+'00000000'+
Isnull(Substring(Str(100000+Max(Right(T0.CardCode,5))+1,6),2,5),'00001')
FROM OCRD T0
WHERE T0.CardCode like '%[0-9][0-9][0-9][0-9][0-9]'
AND T0.CardType = $[$40.0]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.