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
 CASE statement appending whitespace (?)

Author  Topic 

Metcalf
Yak Posting Veteran

52 Posts

Posted - 2009-04-10 : 11:54:28
I'm using a CASE statement to convert an ambiguous char(1) field to something meaningful to laymen. Later on, I stick the info in a DataGrid and do some conditional formatting.

This is the CASE statement:

CASE jodbom.fbomsource 
WHEN 'B' THEN 'Buy'
WHEN 'M' THEN 'Make'
WHEN 'S' THEN 'Stock'
ELSE jodbom.fbomsource
END as SOURCE


While testing the conditional formatting, I notice that one record consistently fails to trigger the formatting, even though it APPARENTLY matches all criteria to do so. But when I test the query in Management Studio, I find this interesting bit:

All 'working' records SOURCE field: 'Buy'
The troubled record's SOURCE field: 'Buy '

When I bypass the CASE statement, all records (including the troubled record) have a jodbom.fbomsource of 'B'.

Anybody have an idea what might be happening here?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-12 : 12:53:59
you're checking only if field has B,M & S values so if source value is 'Buy ' it will be shown as 'Buy ' itself if you've ELSE and NULL otherwise.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-12 : 14:02:05
ELSE RTRIM(jodbom.fbomsource)




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Metcalf
Yak Posting Veteran

52 Posts

Posted - 2009-04-13 : 08:01:17
I wound up having to Substring it once it was in the DataGrid. I'm not dwelling on it, but it was weird that there was no whitespace before the CASE statement, only afterwards. Never seen that before.
Go to Top of Page
   

- Advertisement -