May 23, 2006 at 1:41 pm
I'm a T-SQL newbie. I have a table that contains columns with both <null> and space (blank) values. We'd like to replace these with "n/a". Does anyone have some code to do this?
SQL2K
Thanks
May 23, 2006 at 1:55 pm
It must be done on presentation level, not in database.
_____________
Code for TallyGenerator
May 23, 2006 at 2:08 pm
update table
set field ='N/A'
where isnull(field,' ')=' '
May 24, 2006 at 4:29 am
As post 2 says, at the presentation level, don't update.
Using the principle of post 3:
SELECT (CASE where isnull(field,' ') = ' ' THEN 'N/A' ELSE field END) AS NewField
This should work, since if the field can contain spaces then it must be some sort of char or varchar or whatever.
Remember ISNULL will only work if the two elements have a common data type.
May 24, 2006 at 6:53 am
Thanks to you all. This worked exactly as needed.
May 26, 2006 at 12:54 am
Sometimes, there is no presentation layer...
--Jeff Moden
Change is inevitable... Change for the better is not.
May 26, 2006 at 1:28 am
Actually, there is always a presentation layer.
I know what you're thinking, Jeff, and for pure batch scenarios the 'presentation layer' is the receiving end of a SELECT statement. This may be a file, generated email, console window or whatever, but still it's the 'presentation layer' in this case. What Sergiy is suggesting is that you shouldn't implement the 'N/A' in the model, but at a higher level. (not necessarily to the letter what OSI refers to as presentation layer, though)
/Kenneth
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply