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.
| Author |
Topic |
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-02 : 11:44:13
|
| Need to check if the field has space and nullif (select column from table) not (null and ' ')print 'value exists'how to write IF condition for this??Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-02 : 12:06:36
|
| [code]SELECT CASE WHEN NULLIF(column,' ') IS NOT NULL THEN 'Value Exists' END FROM table[/code] |
 |
|
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-02 : 12:11:07
|
| I tried likedeclare @var varchar (20)set @var = (SELECT column from table ) select @varIF (@var is null) or (@var = '')PRINT 'space'elseprint 'no space'IS this correct way to do???? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-02 : 12:19:08
|
| will this return a single value?else you've to use CASE WHENSELECT column from table |
 |
|
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-02 : 12:28:55
|
| yes that returns a single valueselect distinct column from table where id = 1234 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-03 : 02:20:49
|
quote: Originally posted by visakh16
SELECT CASE WHEN NULLIF(column,' ') IS NOT NULL THEN 'Value Exists' END FROM table
It can also be writtenSELECT 'Value Exists' FROM tableWHERE COLUMN>''MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|