Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL - is not null syntax help - SQL Server 2005

Posted on 2011-03-04
4
Medium Priority
?
432 Views
Last Modified: 2012-05-11
Hello experts,
I have the below snippet of code that is causing me troubles.

declare @HGA1C varchar(30)
set @HGA1C= ''

if (@HGA1C is not null or @HGA1C <> '')
set @HGA1C = CONVERT(VARCHAR(10), convert(datetime,@HGA1C, 101),101 )

select @HGA1C

When I run the above code it returns '01/01/1900'

However, I would like it to simply return a blank segment.  Is there any way to code around this?  My problem is that most of the time this @HGA1C variable HAS a value, but sometimes it is blank - and my if statement above almost seems to be ignored.  

Thanks!
0
Comment
Question by:robthomas09
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 35039431
Try Change
if (@HGA1C is not null or @HGA1C <> '')
to
if (@HGA1C is not null and @HGA1C <> '')
0
 
LVL 23

Assisted Solution

by:Rajkumar Gs
Rajkumar Gs earned 2000 total points
ID: 35039465
the main issue, I noticed is the above.

always the code inside 'if' loop executes and returns the default date of 'datetime' datatype - 01/01/1900

Raj
0
 

Author Closing Comment

by:robthomas09
ID: 35039518
Thanks!
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35039574
Glad I could help you
Raj
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question