473,468 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selecting distinct values from one column with casting

13 New Member
Hello,

I am beginner in MSSQL.

After writing:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT 
  3. DISTINCT UpDate AS ExpirationDate
  4. FROM MyTable
  5.  
I have the following result:

ExpirationDate
------------------------------
1 NULL
2 2007-11-05 12:53:12.000
3 2003-01-14 13:33:12.000
4 2004-01-15 12:34:23.000

But I would like to obtain:

ExpirationDate
-----------------------------
1 ALIVE
2 DEAD
3 ANY

Namely, I would like to check ISNULL. If there is any record with value NULL then I cast it to string "ALIVE".
When there is 1 or more dates I would obtain only 1 record with casted to string "DEAD"
Additionally DB should answer always with record "ANY".

I thougth with Casting all the dates to BIT if they are NULL or not and then select Distinct values from 0s and 1s.

Could You help me? Thank You in advance.
Paul
Apr 13 '10 #1
1 3046
code green
1,726 Recognized Expert Top Contributor
I can only think of using CASE. Not too bad if there is only the three options.
Expand|Select|Wrap|Line Numbers
  1. SELECT CASE WHEN update ISNULL THEN "ALIVE"
  2. WHEN COUNT(update) > 1 THEN "DEAD"
  3. ELSE "ANY" AS ExpirationDate END
  4. FROM MyTable 
  5.  
Apr 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
4
by: rodchar | last post by:
Hey all, Is there a way to get similar functionality as the SELECT DISTINCT records in a SQL Statement when selecting records from a dataset? thanks, rodchar
11
by: Ron L | last post by:
I have a data table that lists a series of items in my database. In my user form, I want the user to be able to filter by a number of criteria (e.g. location, contract, date modified, etc). Other...
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
6
by: issac | last post by:
Hi folks Im trying to do a simple query involving the distinct keyword and an access 2000 db, but have been frittering with it for amost and hour and a half and I cant make it work. This is...
4
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
1
by: sampalmer21 | last post by:
Hi, I want to join two tables together and only select the rows that don't have the same customer first name and last name (see my code below). When I run my code with the DISTINCT keyword, it...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.