Click here to Skip to main content
16,022,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my column should display like this
w0000001
w0000002
w0000003
w0000004
w0000005
w0000006
w0000007
w0000008
w0000009
w0000010
w0000011

please help me..
thanks in advance
Posted

If you need the numbering to be unique, create an int (or bigint) column in your database and let the database generate the unique number for it. You have basically two options, either define an identity for the column or use a sequence to generate the value.

Now what comes to the formatting of the column, of the prefix W is a constant, just concatenate it to the column of the result set. If the W is a changing value, store the prefix in a separate column and when the row is fetched, combine it with the key column value.

But the point is, do not combine an incrementing number to another column, store them separately.
 
Share this answer
 
Comments
Maciej Los 12-Sep-15 14:04pm    
5ed!
 
Share this answer
 
An oldie but a goodie (from a previous post back in the days of CPQA yore):

CREATE TABLE [cpqa].[tbl_SR_employeeInfo](
     [employeeName][nvarchar](359),
         [colorHair][nvarchar](MAX)
          )

CREATE TABLE [cpqa].[tbl_SR_employeeInfoIdx](
   [Idx][int]IDENTITY(1,1),
     [employeeName][nvarchar](359),
         [colorHair][nvarchar](MAX)
          )

Content of employeeInfo.txt a tab-delimited datafile containing example data:
originalgriff    white
ronbeyer    brown
andrekraak    black
codehunt    red

BULK INSERT [cpqa].[tbl_SR_employeeInfo]
    FROM 'C:\USERS\Administrator\desktop\employeeInfo_td.txt'

Now transfer first table data to second table:
INSERT INTO [cpqa].[tbl_SR_employeeInfoIdx]
   SELECT [employeeName], [colorHair] FROM [cpqa].[tbl_SR_employeeInfo]

Now, when you go to query the later table, prefix the indexed field using a filter:
SELECT [Idx], [employeeName], [colorHair],  LEFT(REPLICATE('0', 6), 6-LEN(Idx)) + CAST([Idx] AS [nvarchar](12)) AS [zeropaddedIdx], 'N'+  LEFT(REPLICATE('0', 6), 6-LEN(Idx)) + CAST([Idx] AS [nvarchar](12)) AS [concatenationFinal] FROM [cpqa].[tbl_SR_employeeInfoIdx]

Output:
Idx employeeName    colorHair   zeropaddedIdx   concatenationFinal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1   originalgriff   white       000001          N000001
2   ronbeyer        brown       000002          N000002
3   andrekraak      black       000003          N000003
4   codehunt        red         000004          N000004

As I recall, I unceremoniously made no comment on being given points for posting a good answer. So to those who applauded then, Thank-you.
 
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