Reputation: 1496
I am trying to insert a value in column in Sql Server 2008R2:
Create table Test
(
Age varchar(3) NOT NUll
)
insert into test value ('030')
Output:
30
When i am trying same thing in Sybase:
Output:030
Concern: I need to keep '0' in Sql Server 2008R2 too beacause it is creating some formating issues in the generated output file. Any suggestion how to retain that.
Upvotes: 1
Views: 216
Reputation: 15
'030' without the quotes is just interpreted as the integer 30 by sql server. Also, when you try to insert an integer in a varchar field, it inserts it fine as varchar field accepts any alphanumeric value. However, doing it the other way round might throw an error, as a varchar cannot always be converted to an integer.
Upvotes: 0
Reputation: 2993
the syntax for SQL2008 is a bit different, {}
becomes ()
and insert into [tablename] value ()
becomes insert into [tablename] values ()
so to make it works in SQL2008.
Create table Test
(
Age varchar(3) NOT NUll
)
insert into test values ('030')
SELECT * FROM test
by the way why do you use varchar and not char?
Upvotes: 1