Interview Question in SQL Server 2005


 

Interview Question :: AS function not working


I have the following sp (stripped down version) which functions property, however it does not return a column name, only "(no column name)".  Been working on this for a few days now but getting nowhere.  Does anybody have any suggestions?

Thanks in advance

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON
go
 
ALTER PROCEDURE [dbo].[sp_Test] 
@IncRecIdx int, 
@TmpStr varchar(50),
@WrkStr varchar(8000)
AS
---------------------------------------------------------------------------------
set @TmpStr = (select case when chkInc_Abuse_Alleged = 1 then
'Abuse Alleged' else null end from Incident_4 where IncRecIdx = @IncRecIdx)
if len(@WrkStr) = 0 or @WrkStr is null
   set @WrkStr = @TmpStr
else
   set @WrkStr = @WrkStr + ', ' + @TmpStr
---------------------------------------------------------------------------------
set @TmpStr = (select case when chkInc_Burn = 1 then
'Burn' else null end from Incident_4 where IncRecIdx = @IncRecIdx)
if len(@WrkStr) = 0 or @WrkStr is null
   set @WrkStr = @TmpStr
else
   set @WrkStr = @WrkStr + ', ' + @TmpStr
---------------------------------------------------------------------------------
 
select @WrkStr as StrOut
--exec sp_Incident_4_Test 1001
 

 

Answers to "AS function not working"
RE: AS function not working

ALTER PROCEDURE [dbo].[sp_Test] 
@IncRecIdx int, 
@TmpStr varchar(50),
@WrkStr varchar(8000)
AS
---------------------------------------------------------------------------------
set @TmpStr = (select case when chkInc_Abuse_Alleged = 1 then
'Abuse Alleged'  else null end as 'Column Name'  from Incident_4 where IncRecIdx = @IncRecIdx)
if len(@WrkStr) = 0 or @WrkStr is null
   set @WrkStr = @TmpStr
else
   set @WrkStr = @WrkStr + ', ' + @TmpStr
---------------------------------------------------------------------------------
set @TmpStr = (select case when chkInc_Burn = 1 then
'Burn' else null end as 'Column Name'   from Incident_4 where IncRecIdx = @IncRecIdx)
if len(@WrkStr) = 0 or @WrkStr is null
   set @WrkStr = @TmpStr
else
   set @WrkStr = @WrkStr + ', ' + @TmpStr
---------------------------------------------------------------------------------
 
select @WrkStr as StrOut
--exec sp_Incident_4_Test 1001
 
 
Give a column name or display name after the end statement.

 
Vote for this answer ::  
Update Alert Setting