Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query

Status
Not open for further replies.

goransaler

IS-IT--Management
Mar 6, 2003
56
SE
hello

If i have a table like this

id Actstart Actend Activity
1 12:00 13:00 test1
2 15:15 test2
3 13:00 15;00 test3
4 15:00 test4
and the Actstart and Actend are datetime


and i
use this query


SELECT ID, Actstart, Actend, Activity, CASE WHEN EXISTS
(SELECT *
FROM Activity
WHERE Actend IS NULL) THEN '*' ELSE ' ' END + ' ' + Activity AS Activact FROM Activity
WHERE (Actend IS NULL)


i get

2 15:15 test2 *test2
4 15:00 test4 *test4


i get only the ones whith null in Actend

How do i do to get all ones and the one with <NULL>
in Actend will have a * first in the result of Activact and the other ones will have space first
like this

1 12:00 13:00 test1 test1
2 15:15 test2 *test2
3 13:00 15;00 test3 test3
4 15:00 test4 *test4

Ps I also have a question about if i want the Activact
to only contain 20 letter and the Activity field contain maybe 100

Thanks for any help
 
Me again

I m sorry but i do get a * on everyone
 
Code:
SELECT  ID, Actstart, Actend, 
     substring(Activity,1,20),
     case when actend is null then '*' else ' ' end +
 substring(Activity,1,20)
 FROM         Activity
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top