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

I have a view named as vwEnquiry in which i have two coloumn
1- strBranchCode varchar(10)and
2- datEnquiry datetime

i want to generate a auto generated code
which has formate like strBranchCode+year+month+1,
strBranchCode+year+month+2,
strBranchCode+year+month+3 etc


where the year and the month will be extract from datEnquiry



can any body help me out to write this code in MSSQL


Thanks and regard
Subiya
Posted

Google WITH ROWNUMS, this might be what you'll be looking for for the auto numbering

To get the year you can use DATEPART(year,datEnquiry) and DATEPART(month,datEnquiry) and you'd probably need to cast these if you going to be concatenating them as follows CAST(DATEPART(year,datEnquiry) as VARCHAR)
 
Share this answer
 
v3
Your best bet is to use an index for the 1/2/3 etc and build the rest from there, you can do a select that concatenates values in to one.
 
Share this answer
 
Comments
Gordon Beeming 27-Jul-11 15:28pm    
I think you've misused the term index in your solution. An index in SQL will not give any form of auto numbering to any query
Christian Graus 27-Jul-11 19:01pm    
Yes, you're right. I meant an identity field. Blame the jetlag...

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