February 19, 2009 at 1:36 am
---query to Split Value after comma
declare @a varchar(20)
set @a='Tejindra Singh Barnala';
with tbl_for_csv as
(
select left(@a,charindex('',@a)-1) as val,
stuff(@a+'',1,charindex('',@a),") as col
union all
select cast(left(col,charindex('',col)-1)as varchar(100)),
stuff(col,1,charindex('',col),") from tbl_for_csv where col<>"
)
error getting """Unclosed quotation mark after the character string '
)
'
February 19, 2009 at 2:36 am
First of all, what are you trying to do?
You used double quotes instead of single quotes, you have not added the select query in CTE, you wanted to a split a value after comma but there are not any inclusion of comma in the batch.
--Ramesh
February 19, 2009 at 4:37 am
Actually this code i got from here only.....
and this code is given under the TITLE "Query to split values by Coma """:D
So i tried but i got an error:)
February 19, 2009 at 5:30 am
Hey Try This One Instead:
create table #t (num int)
declare @STRvarchar(500)
select @STR = '4,2,7,7834,45,24,45,77'
declare @sql varchar(8000)
select @sql = 'insert into #t select '+
replace(@str,',',' union all select ')
exec ( @SQL )
select * from #t
if object_id('tempdb..#t') is not null
begin drop table #t end
February 19, 2009 at 11:15 pm
thx for ur suggession but i knw tht very well:)
February 20, 2009 at 1:00 am
So u already knew it...:hehe:
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply