Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 673 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I check if a SQL Server text column is empty?

#11
To get only empty values (and not null values):

SELECT * FROM myTable WHERE myColumn = ''

To get both null and empty values:

SELECT * FROM myTable WHERE myColumn IS NULL OR myColumn = ''

To get only null values:

SELECT * FROM myTable WHERE myColumn IS NULL

To get values other than null and empty:

SELECT * FROM myTable WHERE myColumn <> ''

<br>
And remember use LIKE phrases only when necessary because they will degrade performance compared to other types of searches.
Reply

#12
I know there are plenty answers with alternatives to this problem, but I just would like to put together what I found as the best solution by @Eric Z Beard & @Tim Cooper with @Enrique Garcia & @Uli Köhler.

If needed to deal with the fact that space-only could be the same as empty in your use-case scenario, because the query below will return 1, not 0.

SELECT datalength(' ')

Therefore, I would go for something like:

SELECT datalength(RTRIM(LTRIM(ISNULL([TextColumn], ''))))
Reply

#13
Use [**DATALENGTH**][1] method, for example:


SELECT length = DATALENGTH(myField)
FROM myTABLE





[1]:

[To see links please register here]

Reply

#14
SELECT * FROM TABLE
WHERE ISNULL(FIELD, '')=''
Reply

#15
try this:

select * from mytable where convert(varchar, mycolumn) = ''


i hope help u!
Reply

#16
Instead of using `isnull` use a `case`, because of performance it is better the case.

case when campo is null then '' else campo end

In your issue you need to do this:
```
case when campo is null then '' else
case when len(campo) = 0 then '' else campo en
end
```
Code like this:
```
create table #tabla(
id int,
campo varchar(10)
)

insert into #tabla
values(1,null)

insert into #tabla
values(2,'')

insert into #tabla
values(3,null)

insert into #tabla
values(4,'dato4')

insert into #tabla
values(5,'dato5')

select id, case when campo is null then 'DATA NULL' else
case when len(campo) = 0 then 'DATA EMPTY' else campo end
end
from #tabla

drop table #tabla
```
Reply

#17
DECLARE @temp as nvarchar(20)

SET @temp = NULL
--SET @temp = ''
--SET @temp = 'Test'

SELECT IIF(ISNULL(@temp,'')='','[Empty]',@temp)
Reply

#18
> **It will do two things:**
>
> 1. Null check and string null check
> 2. Replace empty value to default value eg NA.




SELECT coalesce(NULLIF(column_name,''),'NA') as 'desired_name') from table;

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through