Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a table name purchase- the two columns are PurchaseID and PurchaseCode
PurchaseID starts with 100(identity) and I need when my page load my text box show purchasecode =
PO-101 how can i do that. ( here PurchaseID(int), PurchaseCode(Nvarchar(10))


thank you
Posted
Updated 9-May-14 21:05pm
v2

1 solution

check this fiddle [^]

SQL
--using top 1 and order by 
-- if you need to get the full id 
select top  1 SUBSTRING(id,  CHARINDEX('-',id)+1, DATALENGTH(id)), id
from Test order by 1 desc;
-- using max

select max(SUBSTRING(id,  CHARINDEX('-',id)+1, DATALENGTH(id)))
from Test;


If you need to build PO from integer column data then try with

SQL
-- buld PO's from id

select 'PO-' + CONVERT(varchar(10), id) from Test2


Sample[^]
 
Share this answer
 
v2
Comments
afsal.mp 10-May-14 3:04am    
shows error 'Argument data type int is invalid for argument 1 of substring function.

'
DamithSL 10-May-14 3:12am    
check my updated answer
afsal.mp 10-May-14 3:28am    
Thank you.. DamithSL.. It is working...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900