Solved

SQL - is not null syntax help - SQL Server 2005

Posted on 2011-03-04
4
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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