dbTalk Databases Forums  

MAX Problem

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss MAX Problem in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vivek
 
Posts: n/a

Default MAX Problem - 09-23-2005 , 11:36 AM






I have Nvarchar column in which i am storing Series no
and i increment it as max(DocNO)+1 to get next number in series
but it has problem after 9 for 10 it also giving max as 9
what is the problem and solution. Do i need to use cast()?


Reply With Quote
  #2  
Old   
David Gugick
 
Posts: n/a

Default Re: MAX Problem - 09-23-2005 , 11:55 AM






Vivek wrote:
Quote:
I have Nvarchar column in which i am storing Series no
and i increment it as max(DocNO)+1 to get next number in series
but it has problem after 9 for 10 it also giving max as 9
what is the problem and solution. Do i need to use cast()?
Why are you storing what clearly appears to be a numeric value in a
character-based column? Consider using an INT column for storage. You
can cast the column to an int but that doesn't address the design
issues.

--
David Gugick
Quest Software
www.imceda.com
www.quest.com



Reply With Quote
  #3  
Old   
SQL
 
Posts: n/a

Default Re: MAX Problem - 09-23-2005 , 12:18 PM



run the code below and you will understand the problem

declare @1 nvarchar(5),@2 nvarchar(5)
select @1 = '1000'
select @2 ='9'
if @1 > @2
select 'yes'
else
select 'no'
go
declare @1 nvarchar(5),@2 nvarchar(5)
select @1 = '1000'
select @2 ='09'
if @1 > @2
select 'yes'
else
select 'no'

and yes use an identity instead

http://sqlservercode.blogspot.com/



"David Gugick" wrote:

Quote:
Vivek wrote:
I have Nvarchar column in which i am storing Series no
and i increment it as max(DocNO)+1 to get next number in series
but it has problem after 9 for 10 it also giving max as 9
what is the problem and solution. Do i need to use cast()?

Why are you storing what clearly appears to be a numeric value in a
character-based column? Consider using an INT column for storage. You
can cast the column to an int but that doesn't address the design
issues.

--
David Gugick
Quest Software
www.imceda.com
www.quest.com



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.