Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear,

I have table called "Call" the columns are CallNo<numberic>, CallNumber<nvarchar(500)>, CallDate<date>

What i When Call being enter CallNumber should genrate 000001 so on depend upon CallNo.

I used in computed Column Specification Formula, ('00000'+right(CONVERT([nvarchar](250),[CallNo],(0)),(5)))

If CallNo=1 then i shows 000001
but if Call No=100 then shows 00000100

digit are increase. i do'nt want to increase digit
if Call No=100 then i shows 000100

how to do it in SQL.

Thanks
Basit.
Posted
Updated 30-Aug-15 20:36pm
v4

If I understand your situation correctly, I would advice not doing this. It looks like you're trying to automatically generate and store an ordinal number. In my opinion the calculation for the ordinal and ordering should be done in an SQL statement based on some other information, for example time stamps of the call etc.

You already have a CallDate fields so why not use that to order and rank the rows. For example have a look at ROW_NUMBER[^]
 
Share this answer
 
Comments
Schatak 1-Sep-15 2:16am    
Exactly
SQL
SELECT CallNo, RIGHT('000000'+CAST(CallNo AS VARCHAR(6)),6) as CallNumber from YourTable
 
Share this answer
 
v2
Comments
basitsar 31-Aug-15 3:25am    
Thanks Alot Dear
DamithSL 31-Aug-15 3:26am    
You are welcome!
You already have the "right" function, but wrong logic, you should concatenate first then extract the rightmost six digits, like this:
select right('000000'+CONVERT(varchar(6),100),6)
 
Share this answer
 
v2

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