Problem with Selct

Problem with Selct

Post by Michael Loga » Fri, 15 Jun 2001 15:49:45



Problem with select

Here is the code
SELECT First + ' ' + Second + ' ' + Third AS CollegeName FROM copiedcolleges

All first columns have something in them.  A majority of the Second columns
have somthing in them.  A very select few have something in Third column.

This query will only return rows with something in all columns.  If only is
something in the First and Second columns the value will be <Null>.

I'm really trying to bring these three fields into one fields.

TIA

Mike

 
 
 

Problem with Selct

Post by Brian Mora » Fri, 15 Jun 2001 13:31:28


I'm not sure I fully  understand the problem you're having.

But I suspect you're seeing the defined ANSI beavior that 'string' = NULL =
NULL.

To avoid this, could use COALESCE(Second, '')

COALESE returns the first non NULL value from an enumerated list.

So you would end up with 'string' + '' which = 'string'

Brian Moran


Quote:> Problem with select

> Here is the code
> SELECT First + ' ' + Second + ' ' + Third AS CollegeName FROM
copiedcolleges

> All first columns have something in them.  A majority of the Second
columns
> have somthing in them.  A very select few have something in Third column.

> This query will only return rows with something in all columns.  If only
is
> something in the First and Second columns the value will be <Null>.

> I'm really trying to bring these three fields into one fields.

> TIA

> Mike


 
 
 

1. SELCT query help

Could someone help me with a query?

I have a table with the following fields:
1. Timestamp, datetime
2. ItemName, varchar
3. Value, float

Where the primary key is Timestamp and ItemName.

EX:

1/1/2004 12:00:00, 'ITEM_A', 10.0
1/1/2004 12:00:00, 'ITEM_B', 15.0
1/1/2004 12:00:20, 'ITEM_A', 10.5
1/1/2004 12:00:21, 'ITEM_B', 16.0
1/1/2004 12:00:40, 'ITEM_C', 11.0
1/1/2004 12:00:40, 'ITEM_B', 15.9
1/1/2004 12:00:50, 'ITEM_A', 13.0
1/1/2004 12:00:60, 'ITEM_A', 12.0
etc....

I would like to write a query to retrieve the latest value of a given
set of "ItemNames" for example the most recent values of itemnames
"ITEM_A" and "ITEM_C".  The result of the query would be 2 records with
Timestamp, ItemName and Value as fields.

Does anyone know how do do this?

Thanks in advance,

Mike

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----

2. Active Scripting Job Steps

3. SELCT INTO #TEMP EXEC SP_NAME

4. License Limits with MSDN SQL 2000 ?

5. putting conditional clauses into SELCT SPs

6. Forcing running total summaries by page?

7. SELCT DISTINCT Help Please

8. SQL 70

9. calling a stored procedure in a selct query

10. SELCT an EXEC

11. selct ... into and union

12. Using code to selct an item from a DBCombo

13. Problems, problems, problems