Solved

SQL - is not null syntax help - SQL Server 2005

Posted on 2011-03-04
4
334 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 500 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now