Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a value starting with 0 in NVARCHAR column SQL Server

Tags:

sql

sql-server

I am new to SQL Server, I am trying to insert a 6 digit string value into a NVARCHAR column. But it stores the data perfectly until the 6 digit string starts with 0.

Ex: 001212 -->stores as 1212
    121212 -->stores as 121212
    012121 -->stores as 12121
    120121 -->stores as 120121

I searched for the solution on stackoverflow but I can get solution for this .

But I have an idea that validate the string length if it is not 6 digit then adding 0 .

if it is correct can someone help me to do it .

like image 928
Zhu Avatar asked Jan 24 '26 20:01

Zhu


1 Answers

If it's a string work with it like it's a string. That is, enclose literal values in single quotes (and add the Nprefix for nvarchars).

INSERT INTO elbat (nmuloc)
VALUES (N'000007');
like image 128
sticky bit Avatar answered Jan 26 '26 10:01

sticky bit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!