|
-
Apr 22nd, 2006, 04:01 AM
#1
Thread Starter
Fanatic Member
writing SQL statement
Hi
I have an SQL table that contains a Flag field type int(allow null) and many other fields
Field Type
Flag int (allow null)
....
If I don't assign a value to Flag it appears<NULL>
I want to write an SQL statement that returns to me all records having an int value in the Flag
For example
ArticleID Title Category Flag
12 hi Economics <NULL>
13 H R U LAW 1
14 GUG LAW 5
15 HUN POL <NULL>
So I want the SQL statement to return only the 2records having ArticleID=13 and 15 because the other 2 records are not assigned a value in the Flag field
Thanks
-
Apr 22nd, 2006, 04:05 AM
#2
Thread Starter
Fanatic Member
Re: writing SQL statement
So I want the SQL statement to return only the 2records having ArticleID=13 and 15 because the other 2 records are not assigned a value in the Flag field
Sorry I want to correct my question:
I want to display the records having ArticleID=13 and ArticleID=14
-
Apr 22nd, 2006, 04:36 AM
#3
Re: writing SQL statement
SELECT fields FROM tablename WHERE `int` <> NULL
(Or it might be IS NOT NULL. Not sure)
-
Apr 22nd, 2006, 07:26 AM
#4
New Member
Re: writing SQL statement
SELECT * FROM [TABLE NAME] WHERE ArticleID=13 OR ArticleID=14
-
Apr 22nd, 2006, 07:33 AM
#5
Re: writing SQL statement
If this is MS SQL Server then whenever you check the FLAG field for a value in a where clause wrap it in the ISNULL function
Code:
Where IsNull(Flag,0)<>0
This function takes a column (the first parameter) and if it is null replaces it's value with the second column (in this case I specified 0).
Fields that can contain a NULL cannot be easily checked in a WHERE clause, due to the way NULL is never "equal" to anything, thus is "not equal" to everything (or something like that - it's a bit early here!).
Some people say to use the COALESCE() function instead of ISNULL() in order to remain ANSI-standard, but I prefer ISNULL myself.
Why are you allowing NULL values in this column? Why not make the value 0 anyway?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|