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 2005 Forums
 Transact-SQL (2005)
 Coalesce

Author  Topic 

haseeb1431
Starting Member

3 Posts

Posted - 2009-09-12 : 13:07:14
my query returns five rows as
1.null
2.celap
3.null
4.null
5.null

when i use the coalesce to get the data as a single string it works fine for other data but for this it reutrns null and i am excepting it to return celap


here is my query as function

ALTER function [dbo].[abc](
@dep varchar(50),@rollno int)
returns varchar(200)
as
begin
declare @has varchar(200)
select @has=coalesce(@has,'','')+
(
(select branchcode from branch
where branchname=department and
campusid=substring(campus,1,1))
+category
)+','
from f1preferences
where rollno=@rollno and
department=@dep--'Electrical Engineering'
order by studentpreference
return @has
end

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-12 : 13:12:06
try select isnull(branchcode,'')


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-12 : 13:38:43
and also isnull(category,'')


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

haseeb1431
Starting Member

3 Posts

Posted - 2009-09-13 : 08:23:32
i have tried isnull but not working too!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-13 : 13:21:07
are you sure its null and not string 'null'?
Go to Top of Page

haseeb1431
Starting Member

3 Posts

Posted - 2009-09-15 : 14:20:37
these are blank fields of datatype varchar
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-16 : 13:07:05
and you want it as null? your sample data shows the column to contain null values?
Go to Top of Page
   

- Advertisement -