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)
 isnull column vs all columns

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2009-01-03 : 03:23:48
Hello guys
i have a query, which i want to retrieve certain columns, but if a certain column isnull, it should be replaced by another value.

However, I am querying more than one value.

what is wrong here


Select groupID, username, isnull(GroupName,'General Categories') as GroupName, convert(varchar(30), CreateDate ,100) CreateDate, totalnumbers from Groups where username = 'username'

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-03 : 06:03:40
i think that query will work fine
when ever groupname is null u will get the general categories in that columns
u can use coalesce also
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-03 : 06:48:01
i would prefer to use coalesce because of below reason

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-03 : 06:49:06
Also you should strongly consider not converting date into varchar if its for display purpose. formatting should be done at yourfront end as far as possible.
Go to Top of Page
   

- Advertisement -