Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In SQL server database table RentMachine have a column Asset datatype varchar(12).
The requirement is that when user click a dropdown then the next max no of Asset will be shown in a textbox.
Suppose In database the max Asset No is RENT-001.
when user click the dropdown then RENT-002 will be shown in a textbox.
Please help me. Advance thangs.
Posted
Updated 30-Nov-14 23:51pm
v2

Create a Identity column in your table and append that with your Fixed character RENT

as below


SQL
CREATE TABLE t1 
(
 c1 int identity(1,1),
 c2 char(3)
);
GO
INSERT INTO t1 VALUES ('2'), ('37'),('597');
GO
SELECT 'RENT' +REPLICATE('0', 3 - LEN(c1)) + convert(varchar(10),c1) AS 'Varchar Column'
FROM t1;
 
Share this answer
 
Quote:
Auto increment of a field in sql server


Try this :

SQL
create table  #test
(
Id int identity(1,1),
Pid as case  len(Id) when 1 then 'RENT-'+'00'+convert(varchar,ID)
when 2 then 'RENT-'+'0'+convert(varchar,ID)
else 'RENT-'+convert(varchar,ID)
end
)

INSERT INTO #test DEFAULT VALUES
INSERT INTO #test DEFAULT VALUES
select *From #test
 
Share this answer
 
Comments
Sumon562 1-Dec-14 6:16am    
Thank you Me. King Fisher for your kind response.Can you please tell me how can I do it in c#.
King Fisher 1-Dec-14 6:39am    
you could use Dropwown selectedIndex_changed Event .

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