[quote]Originally posted by rett
I am having problems with my store procedure displaying my last column name which is "DISPLAY_CATEGORY_DESC". I am trying to do a select that get the primary key from another table and use that key to do another select to get the description.Not sure if I am doing this the correct way. Thanks for your help.DECLARE @startDate datetimeDECLARE @endDate datetimeDECLARE @cat_lvl1_id varchar(10)DECLARE @lvl1_desc varchar(250)DECLARE @get_desc varchar(250)select d.ENTERED_DATE, d.ADV_NAME_ID, d.COUNT_NAME_ID,select @cat_lvl1_id = (select category_lvl1_id from di_categories where (dir_category_id = get_category_id)) set @get_desc = '' IF @cat_lvl1_id = '' BEGIN SET @lvl1_desc = '' END ELSE BEGIN SET @lvl1_desc = (SELECT TOP 1 CATEGORY_DESCRIPTION FROM DI_CATEGORYDESCS WHERE (CATEGORY_LVL_ID = @cat_lvl1_id)) set @get_desc = @lvl1_desc END select @get_desc as DISPLAY_CATEGORY_DESC -- Return a single column from ( -- Subquery returns 3 colums, none of which are used in the outer select... select cwebs.SESSION_ID, webs.ENTERED_DATE, DIR_CATEGORY_ID as GET_CATEGORY_ID,1 as COUNT_AME_ID FROM di_webclickstats cwebs inner join di_websessions webs on cwebs.session_id = webs.session_id) d where d.ENTERED_DATE between @startDate and @endDate+1
Looks like the query above has some problems. Sounds like you're trying to dynamically select the name of the 3rd column. Not possible without resorting to Dynamic SQL.