Click here to Skip to main content
15,922,894 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
The Nightcoder30-May-08 0:43
The Nightcoder30-May-08 0:43 
GeneralRe: SQL-Instead of null value I have to display the text like NO Pin
r aa j30-May-08 1:03
r aa j30-May-08 1:03 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
Alsvha30-May-08 0:56
Alsvha30-May-08 0:56 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
Giorgi Dalakishvili30-May-08 1:16
mentorGiorgi Dalakishvili30-May-08 1:16 
GeneralRe: SQL-Instead of null value I have to display the text like NO Pin
Hesham Amin1-Jun-08 12:27
Hesham Amin1-Jun-08 12:27 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
Hesham Amin1-Jun-08 12:24
Hesham Amin1-Jun-08 12:24 
QuestionWeird nullable DateTime issue... Pin
Harvey Saayman29-May-08 21:43
Harvey Saayman29-May-08 21:43 
AnswerRe: Weird nullable DateTime issue... Pin
The Nightcoder30-May-08 1:00
The Nightcoder30-May-08 1:00 
You can't normally compare anything to NULL with the = operator (the result isn't true or false, but NULL - anything you do on a NULL is NULL). You need to use IS NULL / IS NOT NULL or COALESCE.

If you KNOW that you're looking for NULL, do this:

... WHERE (thefield IS NULL) OR (thefield < @limit)

or:

... WHERE COALESCE(thefield, '1900-01-01') < @limit

That's assuming you have a suitable "NULL equivalent" value to use (as in 1900-01-01). Note that the YYYY-MM-DD layout is unambiguous and always converts automatically to datetime in SQL, regardless of regional settings. Any other format needs an explicit CONVERT with a style parameter to work internationally. Also - the datetime/smalldatetime are the only times where picking a good minimum value is problematic, because:

datetime: 1753-01-01 is the first valid date.
smalldatetime: 1900-01-01 is the first valid date.

Numeric and string columns are easier.

BONUS:

Sometimes you don't even know what you're looking for (such as in a parameterized query). This is a good one (assuming GroupId can be null but never 0 - as in a foreign key relation with an identity field):

... WHERE COALESCE(GroupId, 0) = COALESCE(@param1, 0)...

Figuring that out a) saved me a lot of IFs and CASEs, and b) made me feel pretty stupid about not having done it sooner...

Peter the small turnip

(1) It Has To Work. --RFC 1925[^]

QuestionGetting size of database programatically using C# or VB.NET Pin
Zerox MXI29-May-08 21:35
Zerox MXI29-May-08 21:35 
AnswerRe: Getting size of database programatically using C# or VB.NET Pin
Hesham Amin30-May-08 5:23
Hesham Amin30-May-08 5:23 
Questionun-cooperative DataSets & TableAdapters Pin
ghazanfarKhan29-May-08 8:23
ghazanfarKhan29-May-08 8:23 
QuestionLotus Notes to SQL Replication Pin
madhuGM29-May-08 5:09
madhuGM29-May-08 5:09 
QuestionUsing select or set with exec Pin
ChrisFarrugia29-May-08 4:23
ChrisFarrugia29-May-08 4:23 
AnswerRe: Using select or set with exec Pin
Alsvha29-May-08 6:08
Alsvha29-May-08 6:08 
AnswerRe: Using select or set with exec Pin
SomeGuyThatIsMe29-May-08 7:59
SomeGuyThatIsMe29-May-08 7:59 
QuestionPrevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 2:22
salon29-May-08 2:22 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 2:28
SomeGuyThatIsMe29-May-08 2:28 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 3:32
salon29-May-08 3:32 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 4:02
SomeGuyThatIsMe29-May-08 4:02 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 6:11
Alsvha29-May-08 6:11 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 7:52
SomeGuyThatIsMe29-May-08 7:52 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 8:29
Alsvha29-May-08 8:29 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 6:15
Alsvha29-May-08 6:15 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 22:41
salon29-May-08 22:41 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
The Nightcoder30-May-08 1:17
The Nightcoder30-May-08 1:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.