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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select as another name 2

Status
Not open for further replies.
Mar 17, 2005
147
US
I have a table with serveral fields. One of the fields is called srctable or source table for short. This field stored the information about which table the record came from. It saves that information as 'dbo.activity', dbo.goals, etc.

Is there a way that I can query the table so that the srctable field will show Activites for all dbo.activity records and Goals for all dbo.goals records.

Thank you kindly,
Steve
 
Code:
select case srctable 
       when 'dbo.activity' then  'Activities'
       when 'dbo.goal' then 'Goals' 
       when '...' then '...'
       else '...'
       end
...
 
Ok great and thanks for all your help. How would I fit your statement below in lets say my select statement below?

SELECT *
FROM admin.src_cache_cah"+tfm_SQLstr+"
ORDER BY eventdate_cah DESC
 
SELECT *
FROM admin.src_cache_cah"+tfm_SQLstr+"
when 'dbo.activity' then 'Activities'
when 'dbo.goal' then 'Goals'
else '...'
end
ORDER BY eventdate_cah DESC

Incorrect syntax near when is what I got.
 
Code:
SELECT *,
  case srctable
       when 'dbo.activity' then  'Activities'
       when 'dbo.goal' then 'Goals'
       when '...' then '...'
       else '...'
       end
FROM admin.src_cache_cah...

--James
 
I got an error saying SQL does not support the case construct?

Steve
 
SELECT *,
case srctable
when 'dbo.activity' then 'Activities'
when 'dbo.goal' then 'Goals'
when 'dbo.technician' then 'Technician Report'
else '...'
end
FROM admin.src_cache_cah

I get

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'srctable'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'srctable'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'srctable'.
 
It doesn't look like the column that contains this data is actually called srctable?

--James
 
Ok that time the query ran sucessfully, however should I be seeing the chages in query analyzer in terms of dbo.activity displayed as Activities?

If so i dont.
thanks again for your help really.

Steve
 
Ok it worked in terms of showing up in query analyzer, however when I call the recordset from within my asp page,
and display it it still shows up as dbo.activity etc...even though the statement you wrote works when I test it. any idea why?
 
Ok I know what it wants, it wants a column name.

How do I assign a column name to this statement so that is shows up as a column name?
 
Code:
SELECT *,
  case srctable
       when 'dbo.activity' then  'Activities'
       when 'dbo.goal' then 'Goals'
       when 'dbo.technician' then 'Technician Report'
       else '...'
       end
  [b]As ColumnName[/b]
FROM admin.src_cache_cah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top