• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 435
  • Last Modified:

SQL - is not null syntax help - SQL Server 2005

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
robthomas09
Asked:
robthomas09
  • 3
2 Solutions
 
Rajkumar GsSoftware EngineerCommented:
Try Change
if (@HGA1C is not null or @HGA1C <> '')
to
if (@HGA1C is not null and @HGA1C <> '')
0
 
Rajkumar GsSoftware EngineerCommented:
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
 
robthomas09Author Commented:
Thanks!
0
 
Rajkumar GsSoftware EngineerCommented:
Glad I could help you
Raj
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now