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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Server2008 - Select Query() ?

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2011-06-11 : 09:15:07
Hi,
I like to have Select Query with comparing values between two fields and resultant as a single field, Is it possible?

Select Field1,
(len(trim(Field2))=0) and len(trim(Field3))>0) then Field3 as CmpField or

(len(trim(Field2))>0) and len(trim(Field3))=0) then Field2 as
CmpField or

(len(trim(Field2))=0) and len(trim(Field3))=0) then Field2 as
CmpField


like the above I want to have a select query...by comparing between Fiedl2 & Field3 and its resultant will give CmpField....

Is It Possible?

Thanks For The Ideas.





Paramu @ PARANTHAMAN

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-11 : 09:37:54
[code]
Select Field1,
case when (len(trim(Field2))=0) and len(trim(Field3))>0) then Field3 as CmpField or
when (len(trim(Field2))>0) and len(trim(Field3))=0) then Field2 as CmpField
or (len(trim(Field2))=0) and len(trim(Field3))=0) then Field2
end as CmpField
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2011-06-11 : 09:44:31
Hi Khtan,
Really You Are Gods Gift For The People Like Me...!!!

Thanks For Your All Replies..

Paramu @ PARANTHAMAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-06-12 : 04:20:35
is trim udf you created? SQL Server doesnt have trim by default.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -