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
 Transact-SQL (2000)
 Case statement ignoring space (PHP & SQL)

Author  Topic 

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2008-04-03 : 17:40:01
I have a sql query that looks something like this:


SELECT Name, Phone, AddrType = (SELECT CASE WHEN IsNull(Expiration, '1/1/2040') <= getdate() THEN '[Retired]' + '(' + Addrtype + ') ' WHEN IsNull(Expiration, '1/1/2040') > getdate() THEN '(' + AddrType + ') ' END)
FROM PhoneBook


See the "') '" after AddrType for both When conditions? That's the source of my frustation right now. In SQL, the query works fine. I have rows where both when conditions are met and a blank space is created for those values under Addrtype in the query result. So, what's my beef? Well, on the php-side, it complies with the first When condition. However, with the second one, it ignores the space after the closing paranthesis, namely "') '". I've tried using replace(), space(), replicate() to remedy the situation but to no avail. Just to give you some clarity, the first when condition will return something like this for in PHP:
quote:

"[Retired](Physical) Joe Smith"


The second when condition looks like this:
quote:

"(Physical)Joe Smith"



See the problem? I don't know why, and I'm not doing anything fancy -- no manipulation whatsoever to AddrType in php, just printing what sql spits out -- but it always ignores the last space for the second when condition and I can't figure out the reason. Maybe others have had this problem. I'd appreciate any help. Thank you.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-04-03 : 17:58:56
It sounds like you have a problem in PHP, not SQL, so a Transact-SQL forum is probably not the best place to get help.



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -