on 03-18-2009 2:20 PM
Dear All,
i have this query for automatic creation of BP code which is used as FMS at the BP bode in BP master data. However, this query works fine when the cardtype is "supplier" but once it is changed to customer, it does not generate any code! Can anyone please correct this query and let me know why is this query not working for the customer?
Declare @A Varchar(10)
Set @A=$[OCRD.Cardtype]
SELECT Top(1)
Case
when @A='s' then 'VE' +
cast((select max(cast(substring(( T0.CardCode ),3,3) as int))+1 from OCRD T0 where cardtype='s')as varchar(10))
--when @A='c' or @A='l'
--then 'CU' +
--cast((select max(cast(substring(( T0.CardCode ),3,5) as int))+1 from OCRD T0 where cardtype='c'or cardtype='l')as varchar(10))
end
from OCRD T0
Thanks in advance,
Joseph Antony
I suggest this one for partner code generation. (Sudau2019s SQL may have problem with generating code for leads.)
If $[OCRD.CardType]='S'
Select 'VE'+isnull(right(str(max(substring(c.CardCode,2,10))+1000000001),5),'00001')
From OCRD c
Where c.CardCode like 'VE[0-9][0-9][0-9][0-9][0-9]'
Else
Select'CU'+isnull(right(str(max(substring(c.CardCode,2,10))+1000000001),5),'00001')
From OCRD c
Where c.CardCode like 'CU[0-9][0-9][0-9][0-9][0-9]'
It generate 5 digits, you can change it to less or more.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you all for worthful suggestions. Really appreciate the efforts, Thank you all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To Joseph:
The process generate the same type code for a lead as a customer, because the later will probably become a customer. And your code also would generate this type.
To Suda:
Your code could generate the same number for a lead as an already existing customer, because it selects the maximum from the equal type partners, and the leads and customers use the same number range.
Joseph,
How are your trigerring this FMS. Is it set to Auto Refresh / manual by Pressing Shift+F2
Check this Query
SELECT CASE WHEN $[OCRD.CardType] = 'S' THEN 'VE' ELSE 'CU' END +
CAST(MAX(substring(T0.CardCode,3,3))+1 AS VARCHAR)
FROM [dbo].[OCRD] T0
WHERE T0.CardType = $[OCRD.CardType]
NOTE: There is no need for Declaring variables or such a convoluted SQL.
Suda
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How many BP in total by your projection? The formula gave too little room to grow. If you will only have maximum of 1000 customers for example, your query may work.
Thanks,
Gordon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Probably there are already customers in the table for who the substring(( T0.CardCode ),3,5) expression is not numeric. You should exclude these from the select.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
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.