January 20, 2009 at 10:42 am
i have table a with two columns..
Testtable
vai1 int
vai2 varchar(50)
values
vai1 =1
vai2= 1234,578
select substring(vai2,charindex(',',vai2),len((vai2)- convert(int,(charindex(',',vai2))))) from testvai where vai1=1
i want to retrive the value 578
please help me on this..
January 20, 2009 at 11:06 am
Based solely on your post the following code works:
create table #TestTable(
vai1 int,
vai2 varchar(50)
);
insert into #TestTable
select 1,'1234,578';
select
right(vai2, len(vai2) - charindex(',',vai2))
from
#TestTable
where
vai1 = 1;
drop table #TestTable;
Next question, what are you trying to accomplish and is the data you posted reflective of all your data?
January 20, 2009 at 11:08 am
i got the expected result by following query...
select substring(vai2,charindex(',',vai2)+1,len(vai2)- convert(int,(charindex(',',vai2)))) from testvai where vai1=2
is ther any simpler way..
Please help me..
January 20, 2009 at 11:10 am
THank you very much..
i got the same result in a simpler way..
select right(vai2, len(vai2) - charindex(',',vai2)) from testvai where vai1=2
Thankq for the quick reply..
January 20, 2009 at 11:12 am
declare @str1 varchar(10)
set @str1='1234,578'
select right(@str1,len(@str1)-charindex(',',@str1))
output
----------
578
(1 row(s) affected)
January 20, 2009 at 11:23 am
i was so slow!!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply