Get the non empty data from a sql_varient column - sql

I have a sql table with sql_varient column. I want to query the table to get the records which has value. I used following query
SELECT *
from Table
WHERE sql_varient_column IS NOT NULL
But its return the data which has no data also. How can I achieve this

To get the row for column sql_varient_column is not null and not empty:
SELECT *
from Table
WHERE NULLIF(sql_varient_column, '') IS NOT NULL

Try this one:
SELECT * FROM Table Where sql_varient_column != ''

I think you want this.
you can try it
SELECT *
from Table
WHERE ISNULL(sql_varient_column,'') != ''

Related

Oracle SQL : How to filter a NUMBER column

The following SQL query :
SELECT * FROM TABLE WHERE column = '%'
will return all lines of the table TABLE.
Now, if my column is a NUMBER. How do I return all lines with a WHERE clause ?
Use CAST function on NumberColumn
SELECT * FROM TABLE WHERE CAST(NumberColumn AS VARCHAR(length)) = '%'
CAST and CONVERT take a default 30 length if not specified. ( Credits to #JaydipJ)
SELECT * FROM TABLE WHERE column = column or column is null
Will return everything and works for every data type.

Sql query to find records with column value is blank

I'm trying to find records with Column value is blank. as you can see in the table I have records with following values when I fire a Distinct query on the Column MOVE_STU.
now I can find all the record with column value related to (1,2,3,4 and 6) but I'm not able to find the records with Column Value related to (5). as there are Thousands of record in the table i'm not able to figure out how should I write query in order to get these records. Kindly help. Thanks in Advance. :)
Use trim and comparison with empty string to get records that contain only whitespaces:
SELECT *
FROM your_table
WHERE LTRIM(RTRIM(MOVE_STU)) = ''
Try something like this:
SELECT * FROM YourTable WHERE LTRIM(RTRIM(YourField)) = ''
This will give you all matches that are empty, or have only whitespace.
How about this ?
SELECT * FROM YourTable WHERE MOVE_STU = ''
SELECT * FROM YourTable WHERE ISNULL(MOVE_STU,'') = ''
You can try this:
If your datatype is int then you have to change in varchar
ALTER TABLE [tbl_name] ALTER COLUMN [MOVE_STU] [VARCHAR(50)];
then run the query:
SELECT * FROM [tbl_name] WHERE MOVE_STU IS NULL;

Getting All Records where Particular Column is empty in Access

I am writing a query in Access where I have to get all the records where a particular column is empty, how I can do this?
This is what I am thinking it should be, but its not working.
SELECT *
FROM TABLE
WHERE PARTICULARCOLUMN = ''
This would handle both empty strings ('') and NULL values in the column.
SELECT *
FROM TABLE
WHERE Nz(PARTICULARFIELD,'') = ''
Try...
WHERE PARTICULARFIELD Is Null
Sample from Web:
SELECT [Table1].[CustomerID], [Table2].[CustomerID]
FROM [Table1] LEFT JOIN [Table2] ON [Table1].[CustomerID] = [Table2].[CustomerID]
WHERE ((([Table 2].[CustomerID]) Is Null));
See: http://www.fabalou.com/access/Queries/isnullquery.asp
In my case, I wanted to find all records with a particular field empty. Not NULL didn't work. This did: WHERE ((Not (table.field)="").
So, to find both the empties and the nulls, just to be sure...
WHERE (((table.field)="" Or (table.field) Is Null)

Checking database for NULL boolean value

I have a field in a table that is boolean, a range of records have no value (not true or false). How do I write my SQL statement to find these?
I have tried the following SQL statements without success:
1) SELECT * FROM table WHERE field = NULL
2) SELECT * FROM table WHERE field != TRUE AND field != FALSE
Any help would be greatly appreciated.
Many Thanks, Ben
In TSQL, you need to use IS rather than = when comparing with NULL:
SELECT * FROM table WHERE field IS NULL
Try
select * from table where field IS null
You want IS NULL I believe:
SELECT * FROM table WHERE field IS NULL

How to query for err in MySQL?

I added a column to my table that does not allow null. I guess that is why some of my rows now have real values in the column but some other rows now have (err) in the column. How can I query for this?
select * from Table where new_column = err
That doesn't work.
select * from Table where new_column='err'
select * from Table where new_column is null I think this will work, but my MySQL skills are rusty