locked
Data type RRS feed

  • Question

  • User1291898626 posted

    My userid column have a primariy key auto increment.

    I want that my column value is starting from 0001 instead of 1. How can i do this.

    I can change userid column datatypee to int(4) but it insert the value from 1.

    Please help.

    Friday, March 30, 2012 5:49 AM

Answers

  • User-638331144 posted

    Add a ZEROFILL attribute to your int column.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2012 11:25 PM

All replies

  • User1288683547 posted

    Its not possible, 0001 or 1 consider numeric 1 only. you can do like create a varchar(4) field, and manual increment as your wishes, or create a trigger.

    Friday, March 30, 2012 6:05 AM
  • User1291898626 posted

    How can i add manual increment or create trigger to do this.

     

    Friday, March 30, 2012 6:48 AM
  • User-638331144 posted

    Add a ZEROFILL attribute to your int column.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2012 11:25 PM
  • User1291898626 posted

    I can do this but it can show 1 when it view in gridview . please help

    Tuesday, April 3, 2012 1:15 AM
  • User1288683547 posted

    you create int auto increment and when you retrive values from that table, use replicate function to fill the zero, or create view

    example

    CREATE TABLE TESTTABLE
    (ID INT PRIMARY KEY IDENTITY(1,1),
     NAME VARCHAR(100))
     
     INSERT INTO TESTTABLE VALUES ('MASTAN')
     INSERT INTO TESTTABLE VALUES ('OLI')
     
     SELECT REPLICATE('0',4-LEN(ID))+CONVERT(VARCHAR,ID) FROM TESTTABLE
     
     CREATE VIEW VIEWTESTTABLE
     AS
     	 SELECT 
    		REPLICATE('0',4-LEN(ID))+ CONVERT(VARCHAR,ID) [ID],
    		NAME
    	 FROM 
    		TESTTABLE
     
     SELECT * FROM VIEWTESTTABLE
     SELECT * FROM VIEWTESTTABLE WHERE NAME LIKE 'OLI'

    Tuesday, April 3, 2012 2:16 AM