Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 ANSI_Padding

Author  Topic 

anuradhay
Starting Member

41 Posts

Posted - 2004-10-28 : 00:38:07
Hi,

if i execute the following stmt, charindex is returning 9. But it should return 0 since there is no blank space in @var. but the variable is char(9) and the actual value assigned has only 8 chars. so a blank space is added to the end. This should be trimmed if i set ansi_padding off. Still it is not working.

declare @var char(9)
select @var = "29/10/04"
select charindex(" ",@var)

if i rewrite the statement as select charindex(" ",rtrim(@var)) then it is returning 0. Why can't i use the ansi_padding setting.. is it only applicable for columns??

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-10-28 : 01:48:19
use patindex instead

select patindex('% %',@var)

--------------------
keeping it simple...
Go to Top of Page

anuradhay
Starting Member

41 Posts

Posted - 2004-10-28 : 03:06:45
Even the patindex is giving the same result
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-10-28 : 05:01:14
quote:
Originally posted by anuradhay

Even the patindex is giving the same result



i copied the one you posted, and the patindex worked, just replace double quotes with single.

declare @var char(9)
select @var = '29/10/04'
select patindex('%%',@var)

--------------------
keeping it simple...
Go to Top of Page

anuradhay
Starting Member

41 Posts

Posted - 2004-10-28 : 05:46:06
it is working
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-10-28 : 06:26:29
just remember, double quote in sql is treated as a character, to indicate a string single quotes are used.

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -