views:

38

answers:

3

I have a column with bigint datatype in SQL Server 2005.

I want to store 0347 in that.. (0 should not be removed) means their must be at least four value like: 0034 , 0007, 0423,4445.

A: 

As far as I know, you can't store formatted data in an integer type field.

Run sprintf or similar over the data when you get it out of the database instead.

David Dorward
+6  A: 

SQL will not store the 0 if you use a bigint.

You could use

select right('00000000'+ltrim(Str(<bigIntField>)),4) as DisplayVal

Change the '4' to what size you want to zero fill the fields to.

Sparky
+2  A: 

You can't store a formatted value like that in an integer field. You'd need to store as a VARCHAR.

Unless you have a very good reason, I'd keep it as you have it in the DB, but just format the number for display in the UI.

AdaTheDev