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
Solved

Sql Statement

Posted on 2014-01-23
4
359 Views
Last Modified: 2014-01-23
I need some help with creating a sql statement that can be used with html page.  I need to pull data from a field within table and show the results as either yes or no
I have two types - one is a date field and the other is either 1 or 0.  The one giving me a problem is the date - the default for the field is 1/1/1900 so I need to show any with this date as no and any with a date other than this as YES.  I hope has enough information for someone to help me if not please let me know.  I have tried this basic statement and customizing for my data and using a date but keep getting errors.

Select Case When IsNull(FieldName, 0) = 1 Then 'Yes' Else 'No' End As FieldName From TableName
0
Comment
Question by:jajen
4 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 150 total points
ID: 39803018
if the field is date data type, then the issue is with the 0 as default value...

this is the way I would start coding:
Select Case When FieldName IS NULL then 'No'
   when FieldName <= convert(datetime, '1900-01-01', 120) then 'No' else 'True' End As FieldName 
From TableName  

Open in new window

0
 
LVL 12

Assisted Solution

by:jmcmunn
jmcmunn earned 150 total points
ID: 39803059
Assuming the field will never be null (since you said you have a default value) it would just be this:

SELECT CASE WHEN [theDateField]= '1900-01-01' THEN 'No' ELSE 'Yes' END AS YesOrNo
FROM [TableName]

Otherwise if it is null, add in another when/where statement for the null value.
0
 
LVL 18

Accepted Solution

by:
x-men earned 200 total points
ID: 39803062
Select Case
  When datefield = '1/1/1900' Then 'no'
Else 'yes'
End As FieldName From TableName
0
 

Author Closing Comment

by:jajen
ID: 39803091
Thank you all for answers - sometimes simple is the way to go - I was making it more difficult than needed.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

837 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