I have a table in a dataset having some columns which is reading from the xml file, in which i want to update a column values in the following way.
1-mon
2-tue
3-wed
4-thu
5-fri
6-sat
7-sun
example data
columnA columnB columnC
dot net 1,2,3
articles forums 1,4,5,6
tech blogs 1,2,3,4,5,6,7
my output should e
columnA columnB columnC
dot net mon,tue,wed
articles forums mon,thu,fri,sat
tech blogs daily
please suggest me .
Loading

VulpesPosted Aug 9, 2012, 10:02 AM
Santhosh Kumar NallavelliPosted Aug 10, 2012, 12:46 AM
Jignesh TrivediPosted Aug 9, 2012, 8:57 AM
you can achive this using UDF.
try...
CREATE FUNCTION dbo.GetDayName(@days VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SET @days = @days+ ','
DECLARE @dayName varchar(10)
DECLARE @retDayName varchar(MAX)
DECLARE @Value VARCHAR(10)
While (Charindex(',',@days)>0)
Begin
Select @Value = ltrim(rtrim(Substring(@days,1,Charindex(',',@days)-1)))
SELECT @dayName = CASE CAST(@Value AS INT)
WHEN 7 THEN 'Sun'
WHEN 1 THEN 'Mon'
WHEN 2 THEN 'Tue'
WHEN 3 THEN 'Wed'
WHEN 4 THEN 'Thu'
WHEN 5 THEN 'Fri'
WHEN 6 THEN 'Sat'
END
Set @days = Substring(@days,Charindex(',',@days)+len(','),len(@days))
if(ISNULL(@retDayName,'')='')
SET @retDayName = @dayName
else
SET @retDayName = ISNULL(@retDayName,'') + ',' + @dayName
End
RETURN (@retDayName)
END
select columnA,columnB,dbo.GetDayName(columnC) from tempTest
hope this will help you.
Abhijit baruaPosted Aug 9, 2012, 8:24 AM
first select then extract value when u get ,(coma) then for each loop through and change on your condition. But i think you should check table normalization.