Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character truncation problem in database 2

Status
Not open for further replies.

btween

Programmer
Joined
Aug 7, 2003
Messages
338
Location
US
I have a page that enters received post values into an ms sql database. The problem is that I get some number like 000450 and upon insertion it is truncated to 450.

I have my db field set as nvarchar 50

am I using the wrong data type for this field?

how can I maintain all 6 numbers in the database?

thanks for your help
 
I thin it depends on how it is being passed in if a number is being passed in to an nvarchar it will get runcated but if text is passed in it stores it as text.

see examples:

Code:
declare @q nvarchar (50)
set @q = 004560
print @q

declare @p nvarchar (50)
set @p = '004560'
print @p

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Something is wrong. It should not do that with a varchar field. The question of datatype depends upon what sort of text you are storing. Do you really need nvarchar rather than char or varchar?
I'm guessing that your front-end is causing the problem.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
HI,
I think DBomrrsm has raised a good point.

B.R,
miq
 
I think Domrrsm cooked-the-books on that example!
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
what do you mean Karl ?

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Code:
[Blue]DECLARE[/Blue] @q [Blue]varchar[/Blue] [Gray]([/Gray]50[Gray])[/Gray]
[Blue]SET[/Blue] @q [Gray]=[/Gray] 004560
[Blue]PRINT[/Blue] @q
But you still maybe right, I simply don't know.
-Karl


[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top