Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create a auto generated quatation number in sql

i have created one table in sql but this table how to genrated a quatation number, each time insert one quatation number created

pls help me anybody
Posted
Updated 8-Jun-15 21:42pm
v2

You could use an Identity column in your table.

Explanation[^]
Documentation[^]

[Edit in response to OP comment]
Primary key is irrelevant.

IDENTITY columns get automatically generated numbers. These may not be sequential as the values are unchanged after deletions (unlike using something like ROWNUMBER() where the numbers will always be regenenerated).

For example, create a sample table
create table CP2
(
	QuoteNo int IDENTITY(10001,1),
	SomeOtherData varchar(max)
)

insert into CP2 values
('item 1'),
('item 2'),
('item 3')
This will automatically generate the QuoteNo values:
10001	item 1
10002	item 2
10003	item 3
You want yours in a particular format - so format them at the point of display e.g.
SQL
SELECT 'QU-' + CAST(QuoteNo as varchar)
from CP2
VB
QU-10001
QU-10002
QU-10003
 
Share this answer
 
v2
Comments
MohamedEliyas 9-Jun-15 3:53am    
i will create primary key id in my table. but i was need another qutation number automaticaly create in each time sir

for example "QU-10001"
"QU-10002"

IN sql query sir
CHill60 9-Jun-15 4:12am    
Primary key id has nothing to do with this. I've added further information to my solution
Maciej Los 9-Jun-15 4:07am    
+5!
CHill60 9-Jun-15 4:13am    
Thank you! Shame the OP didn't understand the links though :(
MohamedEliyas 9-Jun-15 5:10am    
thank u sir. this is exact output sir.thank so much my vote5
 
Share this answer
 
v3
Comments
CHill60 9-Jun-15 4:13am    
Ah - didn't refresh page and have just seen this. +5
Maciej Los 9-Jun-15 4:25am    
Thank you, Caroline.
You can reference this[^] for a quality solution.
 
Share this answer
 

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