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 2000 Forums
 SQL Server Development (2000)
 How would I write this query?

Author  Topic 

sbt1
Yak Posting Veteran

89 Posts

Posted - 2004-02-05 : 07:34:23
I need to check the value of field 'Name' and if it's not blank, trim trailing whitespace and return it; however if 'Name' is blank, return the value of a field named 'Date'.

Not quite sure how to write this query, maybe someone can help me?

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-02-05 : 07:44:10
[code]create table test ( name varchar(30), date datetime)

insert into test select null, getdate()
union all select 'Name',getdate()+1

select case when name is null then convert(varchar(30),date) else rtrim(name) end value
from test[/code]
Go to Top of Page
   

- Advertisement -